I want to give the player that is holding the gear (that is used in this script) some cash right after line 1. The script is in a part, not inside a tool, so I am not sure how I go about this.
script.Parent.Touched:Connect(function(Hit) if Hit.Parent.Name == 'Hamburger' then Hit.Parent:Destroy() script.Parent.Ding:Play() script.Parent.Parent.PlatedBurger.Transparency = 0 wait(6) script.Parent.Parent.PlatedBurger.Transparency = 1 end end)
If you can help, thank you!
The function game.Players:GetPlayerFromCharacter()
would be really useful for this! Your attempt of:
local player = game.Players.LocalPlayer player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 5
would not work as the LocalPlayer
can only be called from a LocalScript. So, how do we use the game.Players:GetPlayerFromCharacter()
function? Well, here's an example.
part.Touched:Connect(function(hit) local player = game.Players:GetPlayerFromCharacter(hit.Parent) if player then --Code end end)
This way, we check if whatever has touched the part actually came from a player in the server.
Hope this helps!