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.
1 | script.Parent.Touched:Connect( function (Hit) |
2 | if Hit.Parent.Name = = 'Hamburger' then |
3 | Hit.Parent:Destroy() |
4 | script.Parent.Ding:Play() |
5 | script.Parent.Parent.PlatedBurger.Transparency = 0 |
6 | wait( 6 ) |
7 | script.Parent.Parent.PlatedBurger.Transparency = 1 |
8 | end |
9 | end ) |
If you can help, thank you!
The function game.Players:GetPlayerFromCharacter()
would be really useful for this! Your attempt of:
1 | local player = game.Players.LocalPlayer |
2 | 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.
1 | part.Touched:Connect( function (hit) |
2 | local player = game.Players:GetPlayerFromCharacter(hit.Parent) |
3 | if player then |
4 | --Code |
5 | end |
6 | end ) |
This way, we check if whatever has touched the part actually came from a player in the server.
Hope this helps!