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

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

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

✓ Accepted answer

(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)

14 comments

0

Thanks! It worked!

0

But I have an endless loop that gives you coins every 5 seconds so whenever it subtracts the currency it comes right back

1

If you need help with it, just ask me!

0

i just did

0

how do i stop it?

0

Maybe try using a boolvalue to stop the loop

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.

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)

0

Can you edit that code into the answer?

0

its local though

0

its local though

0

OH, i get it now. You need it to work on the server now, right?

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

0

Yeah, remotes are probably the way to go.

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