Rit957
|
  |
| Joined: 19 Apr 2011 |
| Total Posts: 3459 |
|
|
| 10 Jan 2015 07:39 PM |
I know why this doesn't work, but how would I make it work?
function onTouched(hit) local humanoid = hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid")
local tool = hit.Backpack:FindFirstChild("M9"); if tool then local clips = tool.Clips.Value tool.Clips.Value = (clips + 1) end end
|
|
|
| Report Abuse |
|
|
Rit957
|
  |
| Joined: 19 Apr 2011 |
| Total Posts: 3459 |
|
| |
|
LucasLua
|
  |
| Joined: 18 Jun 2008 |
| Total Posts: 7386 |
|
|
| 10 Jan 2015 07:49 PM |
For starters whoever wrote that large line of relationship operators wasn't thinking clearly as the operators would still return hit if the Parent did not contain a Humanoid...
You also need to connect the function to some sort of event so that it can interact with the Roblox environment.
Are you looking for this line? :
script.Parent.Touched:connect(onTouched)
|
|
|
| Report Abuse |
|
|
Rit957
|
  |
| Joined: 19 Apr 2011 |
| Total Posts: 3459 |
|
|
| 10 Jan 2015 07:51 PM |
| i know that but i mean when i add that would it work? how would i make it work if it doesnt? |
|
|
| Report Abuse |
|
|
Chrapnel
|
  |
| Joined: 01 Feb 2014 |
| Total Posts: 951 |
|
|
| 10 Jan 2015 07:55 PM |
'I know why this doesn't work, but how would I make it work?'
how does that work ._. |
|
|
| Report Abuse |
|
|
Rit957
|
  |
| Joined: 19 Apr 2011 |
| Total Posts: 3459 |
|
|
| 10 Jan 2015 07:57 PM |
| I know the reason why it doesn't work, it is just I have no clue how I would fix it. |
|
|
| Report Abuse |
|
|
Chrapnel
|
  |
| Joined: 01 Feb 2014 |
| Total Posts: 951 |
|
|
| 10 Jan 2015 07:58 PM |
| well why doesn't it work? might help me help you |
|
|
| Report Abuse |
|
|
Rit957
|
  |
| Joined: 19 Apr 2011 |
| Total Posts: 3459 |
|
|
| 10 Jan 2015 08:00 PM |
It is because when you collide with the part, hit is game.Workspace.Rit957 I can not make it check for game.Players.Rit957.Backpack but only game.Workspace.Rit957.Backpack (which does not exist.) |
|
|
| Report Abuse |
|
|
Chrapnel
|
  |
| Joined: 01 Feb 2014 |
| Total Posts: 951 |
|
|
| 10 Jan 2015 08:40 PM |
db = false
function onTouched() local plr = game.Players.LocalPlayer
db = true local tool = plr.Backpack:FindFirstChild("M9"); if tool then local clips = tool.Clips tool.clips.Value = (clips + 1) wait(1) db = false
end end |
|
|
| Report Abuse |
|
|
Rit957
|
  |
| Joined: 19 Apr 2011 |
| Total Posts: 3459 |
|
|
| 10 Jan 2015 08:51 PM |
| My clips still stayed the same... |
|
|
| Report Abuse |
|
|
Chrapnel
|
  |
| Joined: 01 Feb 2014 |
| Total Posts: 951 |
|
|
| 10 Jan 2015 08:54 PM |
| tool.clips.Value = tool.clips.Value + 1 |
|
|
| Report Abuse |
|
|
2unknown2
|
  |
| Joined: 30 Oct 2011 |
| Total Posts: 9351 |
|
|
| 10 Jan 2015 08:57 PM |
script.Parent.Touched:connect(function(hit) local humanoid = hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") local player = hit.Parent.Name
local tool = game.Players[player].Backpack:FindFirstChild("M9"); if tool then local clips = tool.Clips.Value tool.Clips.Value = tool.Clips.Value + 1
end end) |
|
|
| Report Abuse |
|
|
Rit957
|
  |
| Joined: 19 Apr 2011 |
| Total Posts: 3459 |
|
| |
|
Rit957
|
  |
| Joined: 19 Apr 2011 |
| Total Posts: 3459 |
|
|
| 10 Jan 2015 09:29 PM |
I changed up the code but still no progress
function onTouched(hit) local human = hit.Parent:findFirstChild("Humanoid") local player = game.Players:findFirstChild(hit.Parent.Name) if (human ~= nil) then script.Parent:remove() local Clips = human.Parent.M9.Clips if (Clips~=nil) then Clips.Value = Clips.Value + 1 print "Reloading..." end end end
script.Parent.Touched:connect(onTouched) |
|
|
| Report Abuse |
|
|
Rit957
|
  |
| Joined: 19 Apr 2011 |
| Total Posts: 3459 |
|
|
| 10 Jan 2015 09:45 PM |
| I got it to print reloading but the clips stay the same. |
|
|
| Report Abuse |
|
|
Rit957
|
  |
| Joined: 19 Apr 2011 |
| Total Posts: 3459 |
|
|
| 10 Jan 2015 09:51 PM |
| In theory, it works now. But for some reason. A glitch is the reason it is broken. I will try inside of solo mode. |
|
|
| Report Abuse |
|
|