Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How Would I Award the Player Cash?

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!

3 comments

0

Where's your attempt? I can only see a touch detect script, but no attempt on adding the money

0

LMAOOO

0

I deleted my attempt, because I put something completely wrong. What I did looked a little something like this on Line 3: player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 5 (I defined Player at the top as player = game.Players.LocalPlayer

1 answer

✓ Accepted answer

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!

2 comments

0

thank you :)

0

np

This discussion is preserved as it was. New answers, comments, and votes are closed.