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

How Would I Award the Player Cash?

Asked by 4 years ago

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!

0
Where's your attempt? I can only see a touch detect script, but no attempt on adding the money Leamir 3138 — 4y
0
LMAOOO greatneil80 2647 — 4y
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 Ashton011 30 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

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!

0
thank you :) Ashton011 30 — 4y
0
np Brandon1881 721 — 4y
Ad

Answer this question