This localscript is supposed to weld something to a player, if a value is changed to true, and remove it if it is change to false.
This is a local script in the workspace
local player = game.Players.LocalPlayer local mouse = player:GetMouse() local Magic = player.MagicEquiped -- There is a Boolvalue in the player called MagicEquiped local playername = player.Name mouse.KeyDown:connect(function(key) -- This bit here doesn't even work if key == "q" then if Magic == true then Magic = false elseif Magic == false then Magic = true end end end) Magic.Changed:connect(function() if Magic.Value == true then local hit = game.Workspace[playername] local LeftArm = hit["Left Arm"] if hit:findFirstChild("Humanoid") ~= nil and LeftArm:findFirstChild("MyLeftArm") == nil then g = game.Lighting.MyLeftArm:Clone() g.Parent = LeftArm local C = g:GetChildren() for i=1, #C do if C[i].className == "Part" or C[i].ClassName == "UnionOperation" then local W = Instance.new("Weld") W.Part0 = g.Middle W.Part1 = C[i] local CJ = CFrame.new(g.Middle.Position) local C0 = g.Middle.CFrame:inverse()*CJ local C1 = C[i].CFrame:inverse()*CJ W.C0 = C0 W.C1 = C1 W.Parent = g.Middle end local Y = Instance.new("Weld") Y.Part0 = LeftArm Y.Part1 = g.Middle Y.C0 = CFrame.new(0, 0, 0.05) * CFrame.fromEulerAnglesXYZ(0, 0, 0) Y.Parent = Y.Part0 end end elseif Magic.Value == false then g:remove() end end)
Udated: Oops, missed wait(1) method!
I might solve your code, but first, remember that LOCALSCRIPTS actually work in Workspace. I made a game called Pepsi Escape, it has localscripts in workspace and they work perfectly.
For best results try putting it into StarterPack: Anyway... Here is my fixed code. You missed 'WaitForChild()' function.
But what is WaitForChild()??? WaitForChild is a method that freezes the whole script until the variable (object) gets added.
wait(1) -- I added the wait method to freeze the full script for 1 second, so it detects boolvalue when added (0.999999(...) seconds to be added). local player = game:service("Players").LocalPlayer local mouse = player:GetMouse() local Magic = player:WaitForChild('MagicEquiped') -- There is a Boolvalue in the player called MagicEquiped local playername = player.Name mouse.KeyDown:connect(function(key) -- This bit here doesn't even work if key == "q" then if Magic == true then Magic = false elseif Magic == false then Magic = true end end end) Magic.Changed:connect(function() if Magic.Value == true then local hit = game.Workspace[playername] local LeftArm = hit["Left Arm"] if hit:findFirstChild("Humanoid") ~= nil and LeftArm:findFirstChild("MyLeftArm") == nil then g = game.Lighting.MyLeftArm:Clone() g.Parent = LeftArm local C = g:GetChildren() for i=1, #C do if C[i].className == "Part" or C[i].ClassName == "UnionOperation" then local W = Instance.new("Weld") W.Part0 = g.Middle W.Part1 = C[i] local CJ = CFrame.new(g.Middle.Position) local C0 = g.Middle.CFrame:inverse()*CJ local C1 = C[i].CFrame:inverse()*CJ W.C0 = C0 W.C1 = C1 W.Parent = g.Middle end local Y = Instance.new("Weld") Y.Part0 = LeftArm Y.Part1 = g.Middle Y.C0 = CFrame.new(0, 0, 0.05) * CFrame.fromEulerAnglesXYZ(0, 0, 0) Y.Parent = Y.Part0 end end elseif Magic.Value == false then g:remove() end end)