Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Making script that gives players money when block hits block, help?

Asked by 4 years ago

Trying to make a script that would give player money when a brick hits another brick. The idea would be a player driving this block into another block. Trying to script this here is what I have made to give an insight into what I'm trying to do.

Thanks

Player = game.Players.LocalPlayer
script.Parent.Touched:connect(function(part)
    Player.leaderstats.Money.Value = Player.leaderstats.Money.Value + 1
end)
0
Is it not running the touch event? Touched only runs when the part touching the player is impacted by physics. This means if you cframe a part into another par with a touch event, it won't run the event, but if you push a part into a part with a touch event it will run the touch event so keep that in mind. royaltoe 5144 — 4y
0
 lol! The Reason Why The Touched Event is not firing, is because you haven't even use the "part" Argument! Make sure it finds A Humanoid in that Parts Parent. If it does then Fire the function! lol! Tizzel40 243 — 4y
0
local scripts will not run in the workspace, use a server script and GetPlayerFromCharacter() to get the player DeceptiveCaster 3761 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

What you're doing right now is a bad way of giving money to people.

First of all, you're basically creating an infinite loop of giving the player money because you have no debounces or anything that stops it from running every time it collides with the baseplate, etc. Second of all, you're doing this in a local script (i'm assuming that because localplayer can only be used in a local script) meaning that the changes you make to the money will not be seen by the server and will basically be "fake money".

What you could do instead is this:

--In a server script
Part.Touched:Connect(function(hit)
    local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
    if plr then
        plr:WaitForChild("leaderstats").Money.Value = plr:WaitForChild("leaderstats").Money.Value + 1
    end
end)

You could also add a debounce or a cooldown using wait(seconds) to prevent players from getting like 1000 dollars per second or something.

If this answered your question please mark it as the answer, and comment below if you have any questions.

Ad

Answer this question