01 | function onTouch(hit) |
02 | if hit.Name = = "MoneyBrick" then |
03 | game.Players.LocalPlayer.leaderstats.Money.Value = game.Players.LocalPlayer.leaderstats.Money.Value + 1 |
04 |
05 | hit:Destroy() |
06 |
07 |
08 |
09 | end |
10 | end |
11 |
12 | 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.
01 | function onTouch(hit) --Start the function |
02 |
03 | local check = hit.Parent:FindFirstChild( "Humanoid" ) --Find the human that touched the button |
04 |
05 | if check ~ = nil and script.Parent.Name = = "MoneyBrick" then --If a human is found and the name of the brick is "MoneyBrick" , then |
06 |
07 | local user = game.Players:GetPlayerFromCharacter(hit.Parent) --get player from touching human |
08 | local stats = user:FindFirstChild( "leaderstats" ) --Find moneyholder |
09 |
10 | if stats ~ = nil then --If moneyholder exists then |
11 |
12 | local money = stats:FindFirstChild( "Money" ) --Get money |
13 |
14 | money.Value = money.Value + 1 --amount of money added to the value |
15 |