I am currently trying to make a sandbox tycoon and I put a numbervalue inside of the money (money is like the ore in Miners Haven) that is the value of the money, but I cannot find a way to make it where when it touches a certain part it gets the value from the numbervalue inside of the money and adds it to the Cash value inside of localplayer.leaderstats Please help! This is what I have tried
local repStorage = game:GetService("ReplicatedStorage") function onTouched(hit) if hit.Name == "Cash" then game.Players.LocalPlayer.leaderstats.Cash.value = game.Players.LocalPlayer.leaderstats.Cash.value + hit.Value.Value hit:remove() end end script.Parent.Touched:connect(onTouched)
I am aware that localplayer does not work inside of server scripts, but this is an example of what i need to happen
I don't think remote events are necessary when you want to change a value in the leaderstats. Also I re-wrote your script since it was really confusing to me. Here's the script :
EDIT: I edited the script. Also you'll have to find a way to set the "plrname" to the owner of the tycoon. Maybe when the player touches a part or something it sets a value? Idk. There's multiple ways to do this.
local repStorage = game:GetService("ReplicatedStorage") local plrname = 'InsertNameHere' --Player name local plr = game.Players(plrname) -- Finds player function onTouched(hit) if hit.Name == 'Cash' then plr.leaderstats.Cash.Value = plr.leaderstats.Cash.Value + script.Parent.Cash.Value --Gives money based on value in money script.Parent:Destroy() end end script.Parent.Touched:Connect(onTouched)