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

How do I get this script to work? It is meant to remove the GUI and give a tool.

In Test mode, this script gives the tool and removes the menu gui but when I test it in the real game it doesn't do either.

local StarterGui = game:GetService('StarterGui')
 

Player = game.Players.LocalPlayer

function onClicked()
	while true do
	
		local found = Player.PlayerGui:FindFirstChild("Tool")
		
			if found then
				 				
			else
			wait(.1)			
			
			local clone = game.ServerStorage.Torch:clone()
			game.ServerStorage.Torch.Parent = Player.Backpack
		end
	script.Parent.Parent.Parent:Destroy()
	
	end	
	
	
end
script.Parent.MouseButton1Down:connect(onClicked)

1 answer

✓ Accepted answer

Local Scripts can't access ServerStorage and Scripts can't use LocalPlayer nor PlayerGui. Use a Local script and put the torch in ReplicatedStorage.

--Local Script
local StarterGui = game:GetService('StarterGui')


local Player = game.Players.LocalPlayer

function onClicked()
    while wait() do

        local found = Player.PlayerGui:FindFirstChild("Tool")
            if found then

            else
            wait(.1)            

            local clone = game.ReplicatedStorage.Torch:clone()-- Move item to RS
            game.ServerStorage.Torch.Parent = Player.Backpack
        end
    script.Parent.Parent.Parent:Destroy()

    end 
end

script.Parent.MouseButton1Down:connect(onClicked)

Good Luck

If I helped, please don't forget to accept this answer.

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