Hello, I was scripting a surface gui. The surface gui is a kiosk for my aracde card. Heres the script. If you need more info ask in the answer thing.
playername = script.Parent.Parent.Parent.Parent.Parent.PlayerName.Value script.Parent.MouseButton1Click:Connect(function() script.Parent.Parent.Parent.Tickets.Ticket.Text = game.Players:FindFirstChild(playername).Backpack.Card.Tickets.Value script.Parent.Parent.Parent.Buttons.Visible = false script.Parent.Parent.Parent.Tickets.Visible = true end)
Assuming that you're trying to get the player's name who clicked on the button:
script.Parent.MouseButton1Click:Connect(function(player)--you can get the player who clicked it script.Parent.Parent.Parent.Tickets.Ticket.Text = player.Backpack.Card.Tickets.Value script.Parent.Parent.Parent.Buttons.Visible = false script.Parent.Parent.Parent.Tickets.Visible = true end)
Remember, in all variables use local VARIABLE
not VARIABLE
the local
is more efficient
For first, you can get the player with game:GetService("Players").LocalPlayer
(Only works in LocalScript), and you can simple use player:WaitForChild("Backpack").Card.Tickets.Value
. And use player:WaitForChild("Backpack")
for no errors.
You can see of WaitForChild here: Roblox Wiki - WaitForChild
You can use this:
local player = game:GetService("Players").LocalPlayer player:WaitForChild("Backpack") script.Parent.MouseButton1Click:Connect(function() script.Parent.Parent.Parent.Tickets.Ticket.Text = player:WaitForChild("Backpack").Card.Tickets.Value script.Parent.Parent.Parent.Buttons.Visible = false script.Parent.Parent.Parent.Tickets.Visible = true end)
Hope it helped! :)