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

How come it doesn't get the player of whoever clicked this TextButton?

Asked by 5 years ago
Edited 5 years ago

I have a local script:

script.Parent.Activated:Connect(function(p)
    local cash = p.leaderstats.DepressionCoins.Value
    if p >= 300 then
        p = p - 300
    end

end)

I thought p would mean the parent of whoever clicked it but it didn't. Can someone help?

1 answer

Log in to vote
1
Answered by
BashGuy10 384 Moderation Voter
5 years ago
Edited 5 years ago

(insert something i need to say here)

use game.Players.LocalPlayer

if you are trying to subtract coins from the player do dis

local p = game.Players.LocalPlayer

script.Parent.Activated:Connect(function()
    local cash = p.leaderstats.DepressionCoins
    if cash.Value >= 300 then
        cash.Value = cash.Value - 300
    end

end)
0
Thanks! It worked! User#25281 0 — 5y
0
But I have an endless loop that gives you coins every 5 seconds so whenever it subtracts the currency it comes right back User#25281 0 — 5y
1
If you need help with it, just ask me! BashGuy10 384 — 5y
0
i just did User#25281 0 — 5y
View all comments (10 more)
0
how do i stop it? User#25281 0 — 5y
0
Maybe try using a boolvalue to stop the loop BashGuy10 384 — 5y
0
Well no I want the loop to always be running, but whenever I subtract currency. The loop doesnt know that it has done that so it goes back to its original value. User#25281 0 — 5y
0
game.Players.PlayerAdded:connect(function(p) local stats = Instance.new("IntValue", p) stats.Name = "leaderstats" local money = Instance.new("IntValue", stats) money.Name = "DepressionCoins" money.Value = 0 while true do wait(6) local newmoney = game.Players.LocalPlayer.leaderstats.DepressionCoins money.Value = money.Value + math.random(1,5) end end) User#25281 0 — 5y
0
Can you edit that code into the answer? BashGuy10 384 — 5y
0
its local though User#25281 0 — 5y
0
its local though User#25281 0 — 5y
0
OH, i get it now. You need it to work on the server now, right? BashGuy10 384 — 5y
1
game.Players.LocalPlayer only works on a LocalScript tho, so i dont think the cash would change on everybody screens. use something like a remote event and then use plr something like that when the remote event gets fired idk i've never used remote events my friend taught me this i cant do the whole thing lol TrustedInstaIler 17 — 5y
0
Yeah, remotes are probably the way to go. BashGuy10 384 — 5y
Ad

Answer this question