Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How could I move this localscript over to a normal script? (And still have it functional)

p = game.Players.LocalPlayer
repeat wait() until p:FindFirstChild("Backpack")
function Click()
	wait(2)
repeat wait() until p:FindFirstChild("Backpack")
game.ReplicatedStorage:GetChildren() [math.random(1, #game.ReplicatedStorage:GetChildren())]:clone().Parent = p.Backpack
game.ReplicatedStorage:GetChildren() [math.random(1, #game.ReplicatedStorage:GetChildren())]:clone().Parent = p.Backpack
game.ReplicatedStorage:GetChildren() [math.random(1, #game.ReplicatedStorage:GetChildren())]:clone().Parent = p.Backpack
end

script.Parent.MouseButton1Click:connect(Click)

2 answers

You cant, LocalPlayer is LocalScript only.

1 comment

0

To have it still functional, it may need some edits. Examine the question a little more.

You could try to use this, the only thing You have to do is add Parents to the "local p" cause i don't know exactly where the button is located, i made it so it fits into a [Script > Frame(Or button) > Gui > PlayerGui > Player]

local Count -- Later used
local Stuff = game.ReplicatedStorage:GetChildren()
script.Parent.MouseButton1Click:connect(function() -- Clicker is actually the person that clicks
	local p = script.Parent.Parent.Parent.Parent -- As i see mousebutton1click function i see its a gui, that
	--means that you could do [script.Parent.Parent.Parent] to reach the player itself you may need 						  				                   								--to add more .Parents to it cause i don't know the exact location of the player
	-- And i see you want 3 random objects to clone, that can more easy
	repeat
		Count = Count +1
		Stuff[math.random(1,#Stuff)]:Clone().Parent = p.Backpack
	until Count == 3
end)

Hope this works for you :D if it doesn't work for you, feel free to message me that :P

This discussion is preserved as it was. New answers, comments, and votes are closed.