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
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
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
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.