Klink45
|
  |
| Joined: 06 Jun 2011 |
| Total Posts: 26054 |
|
|
| 25 May 2015 02:05 PM |
I am trying to make the local player get points when a RemoteEvent appears in replicated storage, but this works once, and I was completely confused why until I added some prints:
local ReplicatedStorage = game:GetService("ReplicatedStorage") local p = game.Players.LocalPlayer local Jis = p:WaitForChild("leaderstats").Jis
ReplicatedStorage.ChildAdded:connect(function(Child) print("Detected") wait() if(Child:IsA("RemoteEvent"))then print("RemoteEvent") Child.OnClientEvent:connect(function() print("Client") Jis.Value = Jis.Value +math.random(5, 20) print("Done") end) end end)
The second time I try to use this, "Client" never prints, or anything after that for that matter. I think that's why my points aren't coming. Why and how can I fix this? |
|
|
| Report Abuse |
|
|
|
| 25 May 2015 02:10 PM |
| You don't need to use ChildAdded. |
|
|
| Report Abuse |
|
|
Klink45
|
  |
| Joined: 06 Jun 2011 |
| Total Posts: 26054 |
|
|
| 25 May 2015 02:12 PM |
| Ok, but why not? WaitForChild does the same thing and won't that only run once? |
|
|
| Report Abuse |
|
|
Klink45
|
  |
| Joined: 06 Jun 2011 |
| Total Posts: 26054 |
|
|
| 25 May 2015 02:13 PM |
| And by same thing I mean it doesn't execute the second time. |
|
|
| Report Abuse |
|
|
|
| 25 May 2015 02:14 PM |
Just do something like this:
local ReplicatedStorage = game:GetService("ReplicatedStorage") local Event1 = ReplicatedStorage:WaitForChild("Event1") local Event2 = ReplicatedStorage:WaitForChild("Event2") function onEvent1(arg1, arg2) print(arg1, arg2) end
function onEvent2(arg1, arg2, arg3) print(arg1, arg2, arg3) end
Event1.OnClientEvent:connect(onEvent1) Event2.OnClientEvent:connect(onEvent2) |
|
|
| Report Abuse |
|
|
|
| 25 May 2015 02:15 PM |
| You don't need to add a new remoteevent each time, that's just inefficient. |
|
|
| Report Abuse |
|
|
Klink45
|
  |
| Joined: 06 Jun 2011 |
| Total Posts: 26054 |
|
|
| 25 May 2015 02:15 PM |
| Erm... The thing is, I need it to work an unlimited amount of times. If I'm not mistaken, won't that will only work twice? |
|
|
| Report Abuse |
|
|
Klink45
|
  |
| Joined: 06 Jun 2011 |
| Total Posts: 26054 |
|
|
| 25 May 2015 02:16 PM |
| Oh ok! Then what should I do? |
|
|
| Report Abuse |
|
|
|
| 25 May 2015 02:17 PM |
| No, you're completely mistaken. RemoteEvents and RemoteFunctions can be used as many times as you want, that's the point. |
|
|
| Report Abuse |
|
|
Klink45
|
  |
| Joined: 06 Jun 2011 |
| Total Posts: 26054 |
|
|
| 25 May 2015 02:17 PM |
| Ok, to be more specific, if I use your method, will it only work twice? |
|
|
| Report Abuse |
|
|
|
| 25 May 2015 02:18 PM |
| >>RemoteEvents and RemoteFunctions can be used as many times as you want, that's the point. |
|
|
| Report Abuse |
|
|
Klink45
|
  |
| Joined: 06 Jun 2011 |
| Total Posts: 26054 |
|
|
| 25 May 2015 02:19 PM |
| Alright, I see. So then if I do it the way you did it in your script, it will work however many times I need it to? And also, if that's the case, how come mine isn't working? |
|
|
| Report Abuse |
|
|
|
| 25 May 2015 02:21 PM |
| There is probably an error in your script. Post the output. |
|
|
| Report Abuse |
|
|
Klink45
|
  |
| Joined: 06 Jun 2011 |
| Total Posts: 26054 |
|
|
| 25 May 2015 02:23 PM |
| There is no output, it just stops on the Child.OnClientEvent:connect(function() line the second time I try it for no reason that I can tell. I'll check one more time though. |
|
|
| Report Abuse |
|
|
|
| 25 May 2015 02:25 PM |
| There is obviously some output. Perhaps Jis just doesn't exist yet or something. Regardless, you should be doing what it is you're trying to do from a localscript anyways. |
|
|
| Report Abuse |
|
|
|
| 25 May 2015 02:25 PM |
| I meant you shouldn't be doing this from a localscript. |
|
|
| Report Abuse |
|
|
Klink45
|
  |
| Joined: 06 Jun 2011 |
| Total Posts: 26054 |
|
| |
|
|
| 25 May 2015 02:27 PM |
| Because there is no reason to, and if you were using FilteringEnabled, only the one player would see the change. |
|
|
| Report Abuse |
|
|
Klink45
|
  |
| Joined: 06 Jun 2011 |
| Total Posts: 26054 |
|
|
| 25 May 2015 02:30 PM |
| How else am I supposed to get the money though if it isn't in a local script? And I'm trying to only give one player points. |
|
|
| Report Abuse |
|
|
Klink45
|
  |
| Joined: 06 Jun 2011 |
| Total Posts: 26054 |
|
| |
|
Klink45
|
  |
| Joined: 06 Jun 2011 |
| Total Posts: 26054 |
|
|
| 25 May 2015 02:50 PM |
| Well now I'm completely in the dark. |
|
|
| Report Abuse |
|
|
Klink45
|
  |
| Joined: 06 Jun 2011 |
| Total Posts: 26054 |
|
|
| 25 May 2015 03:00 PM |
AHHHHHHHHHHH I've been stuck on this forever, PLEASE. Can somebody show me a script like this that works or something so I can get some clarity? |
|
|
| Report Abuse |
|
|
|
| 25 May 2015 03:04 PM |
Just do:
function addToStat(player, statName, amount) local stat = player:FindFirstChild("leaderstats") and player.leaderstats:FindFirstChild(statName)
if stat then stat.Value = stat.Value + amount end end
addToStat(game.Players.Player1, "Money", 5) addToStat(game.Players.Player1, "Money", -5) |
|
|
| Report Abuse |
|
|
Klink45
|
  |
| Joined: 06 Jun 2011 |
| Total Posts: 26054 |
|
|
| 25 May 2015 03:07 PM |
| What the heck is that? I truly don't get it. Why is it better than my way? |
|
|
| Report Abuse |
|
|
|
| 25 May 2015 03:10 PM |
| Because you are telling the client to do something when there is no reason to tell the client to do what it is you are telling the client to do, and actually it is something you wouldn't even want the client to do. Also, your script doesn't check to make sure that the stat actually exists. |
|
|
| Report Abuse |
|
|