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

How do I make a textlabel have a players name. Please help?!

Asked by 4 years ago

I have a script and I want the item(Pizza) to go into the players inventory how do I make it work?

local Player =     game.Workspace.Part.SurfaceGui.TextLabel.Text
local PlayerGUI = game.Players.LocalPlayer.PlayerGui

script.Parent.MouseButton1Down:connect(function()
    game.ReplicatedStorage:WaitForChild("Pizza"):Clone().Parent = player.Backpack 
0
u gotta click detector? iuclds 720 — 4y
0
its a mouse down it seems for UI buttons RobloxGameingStudios 145 — 4y

3 answers

Log in to vote
0
Answered by
Lazarix9 245 Moderation Voter
4 years ago
Edited 4 years ago

Try this in a server script inside the button you're tryna click:

local players = game:GetService("Players") --Gets players
local ReplicatedStorage = game:GetService("ReplicatedStorage") --Gets replicatedstorage

players.PlayerAdded:Connect(function(p) --finds player object when player joins

    local pizza = ReplicatedStorage:WaitForChild("Pizza") --finds pizza
    local clonedPizza = pizza:Clone() --clones pizza
    local backpack = p.Backpack --backpack

    script.Parent.MouseButton1Down:Connect(function() --when button clicked

        clonedPizza.Parent = backpack --clone pizza to backpack

    end)

end)


If that won't work I can at least tell you what's wrong with your script:

What's wrong with your script?

local Player =     game.Workspace.Part.SurfaceGui.TextLabel.Text --I am assuming that you wanted to get a player object here, since you had a localscript you could have said game.Players.LocalPlayer
local PlayerGUI = game.Players.LocalPlayer.PlayerGui 

script.Parent.MouseButton1Down:connect(function() 
    game.ReplicatedStorage:WaitForChild("Pizza"):Clone().Parent = player.Backpack --You didn't define what player is, so you can't use it

You also didnt put and end) at the end

There, I'm probably wrong on most of these but whatever

Ad
Log in to vote
0
Answered by
starmaq 1290 Moderation Voter
4 years ago

game.Workspace.Part.SurfaceGui.TextLabel.Text isn't the player, it's just the text of a textbox which a string value. Assuming that this is a local script, beacuse you can only deal with GUIs and refer to the player from there, since all of these things are local, they belong to the computer that a certain player is using and not in the server that connects all players. To refer to the player in a local script you have to do game.Player.LocalPlayer

local player = game.Players.LocalPlayer
local PlayerGUI = game.Players.LocalPlayer.PlayerGui

script.Parent.MouseButton1Down:connect(function()
    game.ReplicatedStorage:WaitForChild("Pizza"):Clone().Parent = player.Backpack 
end)

Also you had some spelling mistakes

0
This didn't help! DennisSense 23 — 4y
Log in to vote
0
Answered by 4 years ago
local Player =     game.Players.LocalPlayer
local PlayerGUI = game.Players.LocalPlayer.PlayerGui
local TextLabel = game.Workspace.Part.SurfaceGui.TextLabel.Text

    TextLabel = Players.Name
    script.Parent.MouseButton1Down:connect(function()
        game.ReplicatedStorage:WaitForChild("Pizza"):Clone().Parent = player.Backpack
end)

I figured it out, I just needed to add the TextLabel = Players.Name and it worked.

Answer this question