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

how can i modify this script so it gives the player money?

Asked by 5 years ago

i made a script that slowly turns a brick invisible but i want it to give the player money when the transparency reaches 0

here is the script:

script.Parent.MouseClick:Connect(function()
    script.Parent.Parent.Transparency = script.Parent.Parent.Transparency + 0.25
    if script.Parent.Parent.Transparency >= 1 then
        script.Parent.Parent:Destroy()
    end
end)

here is what i tried but it didnt work:

script.Parent.MouseClick:Connect(function()
    script.Parent.Parent.Transparency = script.Parent.Parent.Transparency + 0.25
    if script.Parent.Parent.Transparency >= 1 then
        game.Players.LocalPlayer.leaderstats.Money.Value = game.Players.LocalPlayer.leaderstats.Money.Value + 5
        script.Parent.Parent:Destroy()
    end
end)

thanks

0
whats the error you get back from the script? elitekiller2342 87 — 5y
0
I'll make some tests, but what I can say is that your question or script is wrong with the number.... (want when reach transparency 0 or 1?) Leamir 3138 — 5y
0
What kind of script is it and what location is the script. forbrad 2 — 5y

1 answer

Log in to vote
1
Answered by
Leamir 3138 Moderation Voter Community Moderator
5 years ago

Hello, poopypigeon245!

Analysing your script, I can think this is a Server Script(if not change to) so, Sever Scripts don't know who LocalPlayer is, you can use the argument of the click detector to solve this, it gives the player...

Edited Script:

script.Parent.MouseClick:Connect(function(plr) --plr is a reference to the player that cliked
    script.Parent.Parent.Transparency = script.Parent.Parent.Transparency + 0.25
    if script.Parent.Parent.Transparency >= 1 then
        plr.leaderstats.Money.Value = plr.leaderstats.Money.Value + 5 --Changed game.Player.LocalPlayer to plr (the reference to the player)
        script.Parent.Parent:Destroy()
    end
end)

Good Luck with your games

Ad

Answer this question