|
| 16 Apr 2016 08:33 PM |
So, in my game, you need to be able to find magazines to increase the ammo that you are carrying. I have a stored ammo value in the gun, which controls the amount of ammo that you have before you run out. So the magazine needs to be able to change that value. I think the easiest way would be to make the magazine a tool that, when used, changes the value and destroys itself. Does anyone have any way to do this?
|
|
|
| Report Abuse |
|
|
brack4712
|
  |
| Joined: 07 Mar 2009 |
| Total Posts: 243 |
|
|
| 16 Apr 2016 09:13 PM |
If you want to have the magazines randomly spawning around the map and then you click them and they change the value it would be someone like this
Ofc, assuming you have the magazine on the ground, insert a Click Detector and a LocalScript.
Code: function onClicked() game.Players.LocalPlayer.Backpack.Gun.ammo = 25 wait(1) script.Parent:Remove() end
script.Parent.ClickDetector.MouseClick:connect(onClicked)
This should work. |
|
|
| Report Abuse |
|
|
|
| 18 Apr 2016 04:29 PM |
Wait... but where do I put the name of my gun so that it specifies?
|
|
|
| Report Abuse |
|
|
| |
|
| |
|
|
| 20 Apr 2016 04:36 PM |
I don't really recommend using ClickDetectors.
Just use the Button1Down event in UserInputService.
-- 4 8 15 16 23 42 |
|
|
| Report Abuse |
|
|
|
| 21 Apr 2016 08:14 AM |
| Any other ideas? Currently,I'm thinking about making the mag a tool using FunctionOnUse. |
|
|
| Report Abuse |
|
|
|
| 21 Apr 2016 08:27 AM |
this is simple
user input service, detect mouse button 1 down, if the target is the magazine(an object), then change the ammo value in the gun
#Code print("Add 13,000 posts") |
|
|
| Report Abuse |
|
|
|
| 21 Apr 2016 09:03 AM |
| I just need something to work for now until I can find something better. Thanks for the idea though. Anyone else? |
|
|
| Report Abuse |
|
|
| |
|
lululukas
|
  |
| Joined: 23 Aug 2010 |
| Total Posts: 1043 |
|
|
| 21 Apr 2016 11:53 AM |
| You could do a touch instead of click.. |
|
|
| Report Abuse |
|
|
|
| 21 Apr 2016 04:46 PM |
Any other scripts or ideas?
|
|
|
| Report Abuse |
|
|
| |
|
brack4712
|
  |
| Joined: 07 Mar 2009 |
| Total Posts: 243 |
|
|
| 22 Apr 2016 05:30 PM |
| In reply to your question about my reply, you don't need to put the name anywhere. It just changes the ammo. You may need to change the location of the ammo, but other than that, it should work fine. Click detectors are personal preference. If you don't want to use it, fine by me :) |
|
|
| Report Abuse |
|
|
|
| 23 Apr 2016 10:54 AM |
| Thanks. I'll try it now to see if it works. |
|
|
| Report Abuse |
|
|
|
| 23 Apr 2016 06:00 PM |
What do I replace with "Gun"?
Couldn't try it yet, because my guns broke. Trying to fix that. |
|
|
| Report Abuse |
|
|
lululukas
|
  |
| Joined: 23 Aug 2010 |
| Total Posts: 1043 |
|
| |
|
|
| 24 Apr 2016 06:41 AM |
| Tried that. And, yes, I did try to change "ammo" with my ammo value's name. |
|
|
| Report Abuse |
|
|
lululukas
|
  |
| Joined: 23 Aug 2010 |
| Total Posts: 1043 |
|
|
| 24 Apr 2016 11:17 AM |
| Is it in a server or local script? |
|
|
| Report Abuse |
|
|
|
| 24 Apr 2016 11:37 AM |
| Local. In the gun. The gun's name is QBB-95 LSW. It thinks that the "95" is a number value. |
|
|
| Report Abuse |
|
|
lululukas
|
  |
| Joined: 23 Aug 2010 |
| Total Posts: 1043 |
|
|
| 24 Apr 2016 12:12 PM |
function onClicked() game.Players.LocalPlayer.Backpack:FindFirstChild"QBB-95 LSW".ammo = 25 wait(1) script.Parent:Remove() end
script.Parent.ClickDetector.MouseClick:connect(onClicked)
|
|
|
| Report Abuse |
|
|
| |
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 24 Apr 2016 01:45 PM |
Okay listen its not that hard. Either 1. make a gui pop up when you are close to the magazine and if you click a button change the value or 2. change the value when you step over the magazine, or 3. change the value with a brick that is a bit bigger than the magazine but transparency 1 and clicking on it.
magazineBrick.ClickDetector.MouseClick:connect(function(player) local gun = player.Character:FindFirstChild("Gun") if gun then local ammo = gun:WaitForChild("Ammo") ammo.Value = ammo.Value + magazineBrick.MagazineAmmo.Value end end)
|
|
|
| Report Abuse |
|
|
|
| 24 Apr 2016 04:42 PM |
| Um... Also doesn't work. I'm probably doing something wrong. |
|
|
| Report Abuse |
|
|
| |
|