In a script, I have this:
workspace.k.OnServerEvent:connect(function(p)
if script.Parent.Parent.selected.Value == true then
local base = game.Players:WaitForChild("Player1").Character["Right Arm"]
local han = script.Parent.Handle
han.Anchored = true
local w = Instance.new("Weld", han)
w.Part0 = han
w.Part1 = base
w.C0 = CFrame.new(0,1,0)
han.Anchored = false
script.Parent.Parent = p.Character
while true do
wait(0.2)
if p.PlayerGui.ScreenGui.one.selected.Value == false then
p.Character:FindFirstChild("Model"):Destroy()
break
end
end
end
end)
That's what I want to run more than once.
In a localscript, I have this:
tab = {script.Parent.ScreenGui.one, script.Parent.ScreenGui.two}
function hook()
workspace.remote.OnClientEvent:connect(function(num)
for i,v in ipairs(tab) do
if v.Value.Value == num then
script.Value.Value = v.Name
break
end
end
local ui = script.Parent.ScreenGui:FindFirstChild(script.Value.Value)
if ui.selected.Value == true then
ui.selected.Value = false
ui.BorderSizePixel = 1
else
ui.BorderSizePixel = 4
ui.selected.Value = true
workspace.k:FireServer()
for i,v in ipairs(tab)do
if v.Value.Value ~= num and v.selected ~= true then
v.BorderSizePixel = 1
v.selected.Value = false
end
end
end
end)
end
hook()
Basically, I want it to be when you press 1, it'll "select" the UI that corresponds with 1(which it does perfectly right now, that script is far from broken), and then it'll weld the tool that also corresponds with 1 to your hand. Right now, it does this, but it only does it once. After I press 1 again the destroy the tool, it'll destroy it. But if I press 1 again to weld it to my hand again, it wont do anything. Why does it only run once?
