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

How do I get data from a player who clicks a TextButton?

Asked by 9 years ago

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)

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' Goulstem 8144 — 9y
0
or just leaderstats in this manner BSIncorporated 640 — 9y

1 answer

Log in to vote
2
Answered by 9 years ago

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

0
I got the error "attempt to index local 'player' (a nil value)" Redinosaur 0 — 9y
0
ohhh 1 sec BSIncorporated 640 — 9y
0
His code should be a localscript. Goulstem 8144 — 9y
0
Thanks! Redinosaur 0 — 9y
Ad

Answer this question