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

How do I find the player who clicked the button?

If I run this script and click the open button, it does nothing. The clicked value is nil, how do I make the value of clicked the player? (I tested and printed the value of clicked which is nil) I want to make it so when the player clicks the open button, their cash decreases by 10.

local open = script.Parent
local frame = script.Parent.Parent
local closeframe = script.Parent.Parent.Parent.CloseFrame

open.MouseButton1Click:Connect(function(clicked)
		if game.Players:GetPlayerFromCharacter(clicked) then
		clicked.leaderstats.Cash.Value = clicked.leaderstats.Cash.Value - 10
		closeframe.Visible = true	
		end
end)

1 comment

0

Clicked isn't a valid parameter for MouseButton1Click. Just use game.Players.LocalPlayer. This should be in a LocalScript anyways.

1 answer

✓ Accepted answer

Try this: If it doesn't work then put another parent

local open = script.Parent
local frame = script.Parent.Parent
local closeframe = script.Parent.Parent.Parent.CloseFrame

open.MouseButton1Click:Connect(function(clicked)
        local player = clicked.Parent -- here is the code
        if game.Players:GetPlayerFromCharacter(clicked) then
        clicked.leaderstats.Cash.Value = clicked.leaderstats.Cash.Value - 10
        closeframe.Visible = true   
        end
end)

3 comments

0

MouseButton1Click doesn't return anything.

0

10:43:41.275 - Players.soccerstardance251.PlayerGui.ScreenGui.OpenFrame.Open.OpenScript:6: attempt to index nil with 'Parent'

0

Or if its a local script just do local player = game.Players.LocalPlayer

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