Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago

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.

0
Who is the Script??? Eternalove_fan32 188 — 4y
0
put "script.Parent.Unequipped:Connect(function()" outside. OnaKat 444 — 4y
0
and put "local sand = script.Parent.Handle:WaitForChild("Sand")" above equipped and unequipped function OnaKat 444 — 4y
0
yes Eternalove_fan32 188 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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)
Ad

Answer this question