-
What do you want to achieve?
I am trying to make a GUI which when you click freezes the player by welding it to a part when you click it and when you click it again it removes all the weld from the player so the player can move. -
What is the issue?
The code keeps breaking. It does welds the part but I am having problem with making it to toggle. I cant understand/ dont know how to achieve this. -
What solutions have you tried so far?
I have tried making many toggle variables which will check if the code has been toggled or not but it keeps breaking. I have spent 5+ hours on this script trying to figure out and debugging it. I am very confused now.
Code:
Client-Side:
local eventOn = game.ReplicatedStorage.Events.WeldThisNoob
local toggle = false
local eventOff = game.ReplicatedStorage.Events.UnWeldThisNoob
script.Parent.MouseButton1Click:Connect(function()
if toggle == false then
toggle = true
eventOn:FireServer()
else
toggle = false
eventOff:FireServer()
end
end)
Server Side:
local repEvent = game.ReplicatedStorage.Events.WeldThisNoob
local part = game.Workspace.Model.Part
local eventOff = game.ReplicatedStorage.Events.UnWeldThisNoob
local activate = false
local deactivate = false
repEvent.OnServerEvent:Connect(function()
local activate = true
local deactivate = false
part.Touched:Connect(function(hit)
if activate == true and deactivate == false then
hit.Parent.Humanoid.WalkSpeed = 0
hit.Parent.Humanoid.JumpPower = false
hit.Parent:WaitForChild("Right Arm")
hit.Parent:WaitForChild("Left Arm")
hit.Parent:WaitForChild("Right Leg")
hit.Parent:WaitForChild("Left Leg")
hit.Parent:WaitForChild("Torso")
hit.Parent:WaitForChild("Head")
local LeftFoot = Instance.new("WeldConstraint")
LeftFoot.Parent = hit.Parent
LeftFoot.Part0 = part
LeftFoot.Part1 = hit.Parent["Left Leg"]
local RightFoot = Instance.new("WeldConstraint")
RightFoot.Parent = hit.Parent
RightFoot.Part0 = part
RightFoot.Part1 = hit.Parent["Right Leg"]
local RightArm = Instance.new("WeldConstraint")
RightArm.Parent = hit.Parent
RightArm.Part0 = part
RightArm.Part1 = hit.Parent["Right Arm"]
local LeftArm = Instance.new("WeldConstraint")
LeftArm.Parent = hit.Parent
LeftArm.Part0 = part
LeftArm.Part1 = hit.Parent["Left Arm"]
local Head = Instance.new("WeldConstraint")
Head.Parent = hit.Parent
Head.Part0 = part
Head.Part1 = hit.Parent["Head"]
end
while wait() do
if activate == false and deactivate == true then
if hit.Parent.Humanoid then
hit.Parent.Humanoid.WalkSpeed = 16
hit.Parent.Humanoid.JumpPower = 50
local Character = hit.Parent
for i, y in ipairs(Character:GetDescendants()) do
if y:IsA("WeldConstraint") then
y:Destroy()
end
end
end
end
end
end)
end)
eventOff.OnServerEvent:Connect(function()
activate = false
deactivate = true
end)
while wait(5) do
print( deactivate, activate)
end
Any ideas or tip on how I can achieve this will be very much appreciated