I’m having issues With my script It seem to not Add cash to the leaderstats, I’ve tried getting the Service from SrciptService but it don’t nothing.
If someone Could help Me It Would be Really Helpful
Normal Script in the Part
local Player = game.Players.LocalPlayer
local leaderstats = game:GetService("ServerScriptService")
script.Parent.Touched:connect(function(hit)
local Humanoid = hit.Parent:FindFirstChild("Humanoid")
if Humanoid then
Player.leaderstats.Cash.Value = Player.leaderstats.Cash.Value + 1500
else
warn("Error")
end
end)
Leaderstats Script
game.Players.PlayerAdded:Connect(function(player)
local leaderstats= Instance.new("Folder")
leaderstats.Name= ("leaderstats")
leaderstats.Parent= player
local Cash= Instance.new("IntValue")
Cash.Name= ("Cash")
Cash.Parent = leaderstats
Cash.Value = 0
end)
local leaderstats = game:GetService("ServerScriptService")
debounce = false
script.Parent.Touched:connect(function(hit)
local Humanoid = hit.Parent:FindFirstChild("Humanoid")
if Humanoid and debounce == false then
debounce = true
local Player = Players:FindFirstChild(hit.Parent.Name)
Player.leaderstats.Cash.Value = Player.leaderstats.Cash.Value + 1500
else
warn("Error")
end
debounce = false
end)
local debounce = false
script.Parent.Touched:connect(function(hit)
local Humanoid = hit.Parent:FindFirstChild("Humanoid")
if Humanoid and debounce == false then
debounce = true
local Player = Players:FindFirstChild(hit.Parent.Name)
Player.leaderstats.Cash.Value += 1500
task.wait(how mouch time you want to wait )
debounce = false
end
end)
Since this is inside of a normal script, it needs to be a local script and then you’ll need to make a change to the normal script that can give the cash through a remote event inside of ReplicatedStorage. Try something such as this;
Local Script inside of StarterPlayerScripts
game.Workspace.PartNameHere.Touched:Connect(function()
local Key = "KeyHere"
game.ReplicatedStorage.RemoteEvent:FireServer(Key)
script.Disabled = true
end)
Normal Script Inside of ServerScriptService
game.Players.PlayerAdded:Connect(function(player)
local leaderstats= Instance.new("Folder")
leaderstats.Name= ("leaderstats")
leaderstats.Parent= player
local Cash= Instance.new("IntValue")
Cash.Name= ("Cash")
Cash.Parent = leaderstats
Cash.Value = 0
local GivenFreeCash = Instance.new("BoolValue",player) GivenFreeCash.Name = "GivenFreeCash"
end)
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(plr,key)
if key == "KeyHere" and plr.GivenFreeCash == false then
plr.leaderstats.Cash.Value += 1500
plr.GivenFreeCash = true
end
end)
This should work if I am correct, also change “KeyHere” to whatever you want the key to be, and change “PartNameHere” to the name of the part. Let me know if anything is wrong.