This is the click function inside a local script inside a TextButton on a ScreenGui. It should clone the tool on the player's backpack (plr.Backpack). The problem is that the script won't find the player on Roblox Player, it works on the studio when I define plr as game.Players.LocalPlayer, but not on Roblox player when I test it there. Please help me.

function onClick()
	local plr = game.Players.LocalPlayer
	script.Parent.Parent.Visible = false
	script.Parent.Parent.Parent.Done.Visible = true
	tool1:Clone().Parent = plr.Backpack
	tool2:Clone().Parent = plr.Backpack
	tool3:Clone().Parent = plr.Backpack
	tool4:Clone().Parent = plr.Backpack
	tool5:Clone().Parent = plr.Backpack
end

script.Parent.MouseButton1Click:Connect(onClick)

All the variables are defined, the problem isn't there.

4 comments

0

Wait, the local script cant find the player through game.Players.LocalPlayer outside of studio? The ScreenGui is in startergui correct?

0

You shouldn't have to define player within the function, You can define that before the function.

0

Karem, it's not, it clones from a part to PlayerGui

0

Golden, would that fix it?