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 get data from a player who clicks a TextButton?

I've been working on an inventory GUI and I want to change the stats of a player when they click this button. I've tried making my own code but it hasn't worked out so far. This is what I've tried

function click(player)
	
local stats = player:FindFirstChild("leaderstats")
if stats then
	
if stats ~= nil then
	 local cash = stats:findFirstChild("Genie")
end

script.Parent.Visible = false
script.Parent.Parent.Cancel.Visible = false

wait(0.1)
script.Parent.Parent.TextLabel.Text = "."
wait(0.3)
script.Parent.Parent.TextLabel.Text = ".."
wait(0.3)
script.Parent.Parent.TextLabel.Text = "..."
wait(0.3)
script.Parent.Parent.TextLabel.Text = "Purchase successful!  This item has been added to your inventory"
wait(3)	

print('item')

cash.Value = 1

script.Parent.Parent:TweenPosition(UDim2.new(0, 1500,0, 160), "Out", "Bounce")

end
end

script.Parent.MouseButton1Click:connect(click)

2 comments

0

I suggest you don't use 'data' in your title, as that makes people assume you're talking about DataStores or Data Persistence. A better word would be 'statistics'

0

or just leaderstats in this manner

1 answer

✓ Accepted answer

Well you don't need if:statsthen twice...

script.Parent.MouseButton1Down:connect(function())
local player = game.Players.LocalPlayer
local stats = player:FindFirstChild("leaderstats")
if stats then
local cash = stats:findFirstChild("Genie")
script.Parent.Visible = false
script.Parent.Parent.Cancel.Visible = false
wait(0.1)
script.Parent.Parent.TextLabel.Text = "."
wait(0.3)
script.Parent.Parent.TextLabel.Text = ".."
wait(0.3)
script.Parent.Parent.TextLabel.Text = "..."
wait(0.3)
script.Parent.Parent.TextLabel.Text = "Purchase successful!  This item has been added to your inventory"
wait(3) 
print('item')
cash.Value = 1
script.Parent.Parent:TweenPosition(UDim2.new(0, 1500,0, 160), "Out", "Bounce")
end
end
end

Your end was also misplaced, let me know if this works, if it does please accept my answer

4 comments

0

I got the error "attempt to index local 'player' (a nil value)"

0

ohhh 1 sec

0

His code should be a localscript.

0

Thanks!

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