|
| 20 Jul 2016 06:22 PM |
i have this script and local script thats supposed to increase a value(which is the games currency) when the brick is touched the first time it works fine, but the second time the value doesnt increase a bit the output is clean how come its doing this?
the server script: function onTouch(hit) if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then local event = Instance.new("RemoteEvent") event.Parent = game:GetService("Lighting") event.Name = "CoinEvent" event:FireClient(game:GetService("Lighting")) print("Event fired") wait(0.1) script.Parent:Destroy() end end
script.Parent.Touched:connect(onTouch)
the localscript:
game.Lighting:WaitForChild("CoinEvent").OnClientEvent:connect(function() print("Ok") local plr = game:GetService("Players").LocalPlayer local Reward = math.random(6, 9) plr.PlayerGui.Stats.Holder.Money.Value.Value = plr.PlayerGui.Stats.Holder.Money.Value.Value + Reward end)
|
|
|
| Report Abuse |
|
|
kools
|
  |
| Joined: 11 Jan 2009 |
| Total Posts: 1659 |
|
|
| 20 Jul 2016 06:49 PM |
You destroy the parent of the script so the script is destroyed and won't run anymore.
Unless there are multiple things with this script in them? Also be sure to not use Lighting anymore for storing things to be replicated. I suggest using ReplicatedStorage. |
|
|
| Report Abuse |
|
|
|
| 20 Jul 2016 06:53 PM |
@kools
what if you set the parent of the script to nil?
can you destroy the parent of nil? |
|
|
| Report Abuse |
|
|
| |
|
|
| 20 Jul 2016 07:16 PM |
why should i use replicatedstorage?
is it like more efficent? |
|
|
| Report Abuse |
|
|
|
| 20 Jul 2016 07:23 PM |
i changed script.Parent:Destroy() into event:Destroy() so it destroys the event instead, but still doesnt work it prints the Event fired and the ok the first time, but the second time i only see the event fired.
w0t |
|
|
| Report Abuse |
|
|
|
| 20 Jul 2016 07:25 PM |
i made a couple tweaks to my server script, but still no signs of success:
function onTouch(hit) if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then local event = Instance.new("RemoteEvent") event.Parent = game:GetService("Lighting") event.Name = "CoinEvent" event:FireClient(game:GetService("Lighting")) print("Event fired") event:Destroy() script.Disabled = true end end
script.Parent.Touched:connect(onTouch)
|
|
|
| Report Abuse |
|
|
| |
|