Hello,
I made a script that lets you press E to break your leg. Your HRP gets anchored and you can’t move. I use a .Changed event to detect when a BoolValue changes inside the Character. It works fine once, but does not work after I do it once. I’ve used print statements in the code and have deduced that the issue comes from the .Changed event. Here is the code.
(uis script)
local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.E then
print("pressed e")
game:GetService("ReplicatedStorage").legBroke:FireServer()
end
end)
(server script to recieve event)
game:GetService("ReplicatedStorage").legBroke.OnServerEvent:Connect(function(player)
print("e recieved")
player.Character.legBroken.Value = true
end)
(leg break, this is in startercharacterscripts)
local legBroken = Instance.new("BoolValue")
legBroken.Parent = script.Parent
legBroken.Value = false
legBroken.Name = "legBroken"
legBroken.Changed:Connect(function(value)
print("changed")
if value == true then
print("leg broke")
script.Parent.HumanoidRootPart.Anchored = true
script.Parent.Torso["Left Hip"].Enabled = false
end
end)
(leg fix, again in startercharacterscripts)
local clickDetector = Instance.new("ClickDetector")
clickDetector.Parent = script.Parent
local isDoctor = Instance.new("BoolValue")
isDoctor.Parent = script.Parent
isDoctor.Name = "isDoctor"
isDoctor.Value = true
clickDetector.MouseClick:Connect(function(playerWhoClicked)
if isDoctor.Value == true then
playerWhoClicked.Character:FindFirstChild("Humanoid").Health += 30
clickDetector.Parent:FindFirstChild("Humanoid").Health += 30
clickDetector.Parent.Torso["Left Hip"].Enabled = true
clickDetector.Parent.HumanoidRootPart.Anchored = false
print("leg fixed")
else
print("you no qualify")
end
end)
The only thing that prints the second time is “e recieved”
Does anyone have any idea what could be causing this, or does anyone have an alternative to the .Changed event that might work better?
Thanks.