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

My tool clones a GUI once equipped, but it suddenly still work once I unequipped it!?

So, I was working on the magic game "Elemental Magic", I was planning a magic called Sand Magic to have full spell moveset in a GUI, then it works. Suddenly this is the hardest part, cloning it to the PlayerGui.

local UIS = game:GetService("UserInputService")
local s = true
local player = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait()
local gui = player:WaitForChild("PlayerGui")
script.Parent.Equipped:Connect(function()
	local sand = script.Parent.Handle:WaitForChild("Sand")
	sand.Parent = gui
	sand.Enabled = true
	script.Parent.Unequipped:Connect(function()
		sand.Parent = script.Parent.Handle
	end)
end)

I tried the Destroy method, instead it errors the GUI by the spells not making it do it.

4 comments

0

Who is the Script???

0

put "script.Parent.Unequipped:Connect(function()" outside.

0

and put "local sand = script.Parent.Handle:WaitForChild("Sand")" above equipped and unequipped function

0

yes

1 answer

But you have to reuse "sand" so it doesn't make sense if you destroy it forever. Prefer to use the:

local Debris = game:GetService("Debris")
local player = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait()
local gui = player:WaitForChild("PlayerGui")
local sand = script.Parent.Handle:WaitForChild("Sand"):Clone
local sand.Name = "Sand"
sand.Parent = gui

script.Parent.Unequipped:Connect(function()
        Debris:AddItem(sand, 5)
end)

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