Why doesnt the loop break?

So I made a script that takes damage then if the player Hit value is set to true the loop breaks but it doesn’t work:

wait(0.1)
local Players = game:GetService("Players")
local plr = script.Parent.Parent.Parent
local char = plr.Character
local equipped = false
local attacking = false
local RaycastHitbox = require(game.ReplicatedStorage.RaycastHitbox)
local Hitbox = RaycastHitbox:Initialize(script.Parent.Handle)
local Hitbox2 = RaycastHitbox:Initialize(script.Parent.Handle2)
local attack = char.Humanoid:LoadAnimation(script.Animations.Attack)
	Hitbox.OnHit:Connect(function(hit, humanoid)
if humanoid.Parent ~= char and humanoid.Parent.Transformed.TransformedTrue.Value ~= true then
		local player2 = Players:GetPlayerFromCharacter(humanoid.Parent)
		player2.PlayerGui.Struggle.Handler.Disabled = false
		player2.PlayerGui.Struggle.Frame.Visible = true
		player2.PlayerGui.Struggle.StruggleOn.Value = true
		print(humanoid.Parent.name)
		local GrabWeld = Instance.new("Weld",humanoid.Parent.HumanoidRootPart)
		GrabWeld.Name = "GrabWeld"
		humanoid.Parent.HumanoidRootPart.Position = script.Parent.Parent.HumanoidRootPart.Position + Vector3.new(0,0,-1)
		GrabWeld.Part0 = script.Parent.Parent.HumanoidRootPart
		GrabWeld.Part1 = humanoid.Parent.HumanoidRootPart
		GrabWeld.C0 = CFrame.new(0,0,-1)
		
		
		script.Parent.Parent.Humanoid.WalkSpeed = 5
		script.Parent.Parent.Humanoid.JumpPower = 0
		script.Parent.Parent.Humanoid.AutoRotate = true
		
		humanoid.PlatformStand = true
		humanoid.AutoRotate = false
		
local BreakValue = player2.PlayerGui.Struggle.Break
		
repeat
wait(0.2)
humanoid:TakeDamage(2)
print("damage")
until script.Parent.Parent.Transformed.Hit.Value == true or humanoid.Health <= 2 or script.Parent.Parent.Transformed.Hit.Value == true or humanoid.Parent.Transformed.Value == true or script.Parent.Parent.Humanoid.Health <= 0 or equipped == false
		
if script.Parent.Equipped == false then
			GrabWeld:Destroy()
		player2.PlayerGui.Struggle.Handler.Disabled = true
		player2.PlayerGui.Struggle.Frame.Visible = false
		player2.PlayerGui.Struggle.StruggleOn.Value = false
		script.parent.parent.Humanoid.WalkSpeed = 18
		script.parent.parent.Humanoid.JumpPower = 40
		script.parent.parent.Humanoid.AutoRotate = true
		humanoid.AutoRotate = true
		humanoid.PlatformStand = false
		humanoid.Parent.Transformed.Hit.Value = false	
end

this is the script inside the GUI which changes the Break Value:

local Value = script.Parent.Frame.Struggle.Struggled
local StruggleOn = script.Parent.StruggleOn
local BreakValue = script.Parent.Break

game:GetService("UserInputService").InputBegan:connect(function(inputObject, gameProcessedEvent)
	if StruggleOn.Value == true then
		 if inputObject.KeyCode == Enum.KeyCode.Space then
        	Value.Value = Value.Value - 1
		end
    end 
end)


Value.Changed:Connect(function()
	script.Parent.Frame.Struggle.Text = Value.Value
	if Value.Value == 0 then
		game.Players.LocalPlayer.Character.HumanoidRootPart:FindFirstChild("GrabWeld"):Destroy()
		script.Parent.Frame.Visible = false
		BreakValue.Value = true
		script.Disabled = true
		Value.Value = 15
	end
end)
1 Like

Well, the second script within the GUI is a local script, and I assume the first script is a server script? If you’re changing the value on the client, the server isn’t going to see that change. If you want the server to communicate with the client, and vise versa, you should check out: Remote Functions & Events.

Adding on, this is not an efficient way to do things. It would be easiest to use RemoteEvents as I linked above, or placing a value under the player. Relying on values placed under the playergui (unless it is specifically for local use within the GUI) isn’t a good idea.

2 Likes