function onTouch(hit) if hit.Name == "MoneyBrick" then game.Players.LocalPlayer.leaderstats.Money.Value = game.Players.LocalPlayer.leaderstats.Money.Value + 1 hit:Destroy() end end script.Parent.Touched:connect(onTouch)
This script makes it so when a "MoneyBrick" goes over the block the script is in it deletes it and then give you 1 money.
Having a 'LocalPlayer' inside a server script will not work among in-game play. The script below is a modified version, which checks to see the player for touching the brick and checks the name. The script below is supposed to be put into the brick and in a server script, not a local script.
function onTouch(hit) --Start the function local check = hit.Parent:FindFirstChild("Humanoid") --Find the human that touched the button if check ~= nil and script.Parent.Name == "MoneyBrick" then --If a human is found and the name of the brick is "MoneyBrick" , then local user = game.Players:GetPlayerFromCharacter(hit.Parent) --get player from touching human local stats = user:FindFirstChild("leaderstats") --Find moneyholder if stats ~= nil then --If moneyholder exists then local money = stats:FindFirstChild("Money") --Get money money.Value = money.Value +1 --amount of money added to the value script.Parent:Destroy() --destroy the brick end else print("Not named correctly.") --If the name is not correct, it will just print this. end end script.Parent.Touched:connect(onTouch) --Calls the function