I want my code to constantly check if the player is inside the hitbox area. However, it stops when it checks for magnitude > 10, and I can't figure out why.
player = game.Players.LocalPlayer repeat wait() until player:HasAppearanceLoaded() == true while true do wait() local magnitude = (player.Character.UpperTorso.Position - game.Workspace.GetOn.Position).magnitude print(magnitude) if magnitude <9.9 then if player and script.Parent.getOnScriptMoved.Value == false then getOnScript = game.ServerStorage.GetOnFrame:Clone() getOnScript.Parent = player:WaitForChild("PlayerGui") wait() script.Parent.getOnScriptMoved.Value = true end elseif magnitude >10 then guiLocation = player:WaitForChild("PlayerGui") if guiLocation.GetOnFrame then guiLocation.GetOnFrame:Destroy() end end end
I figured out a way to recode this, and my problem has been resolved. I made two separate local scripts and put them inside StarterPlayer.StarterPlayerScrips, and messed with the code a bit. Here is what I put in each one to make it work.
player = game.Players.LocalPlayer repeat wait() until player:HasAppearanceLoaded() == true wait() game.Workspace.GetOn.Touched:Connect(function() local magnitude = (player.Character.UpperTorso.Position - game.Workspace.GetOn.Position).magnitude if magnitude <9.9 and game.Workspace.GetOn.Value.Value == false then wait() if player and game.Workspace.GetOn.Value.Value == false then getOnScript = game.Workspace.GetOnFrame:Clone() getOnScript.Parent = player:WaitForChild("PlayerGui") wait() game.Workspace.GetOn.Value.Value = true end end end)
player = game.Players.LocalPlayer repeat wait() until player:HasAppearanceLoaded() == true wait() game.Workspace.Baseplate.Touched:Connect(function() local magnitude = (player.Character.UpperTorso.Position - game.Workspace.GetOn.Position).magnitude if magnitude >9.9 and game.Workspace.GetOn.Value.Value == true then wait() if player and game.Workspace.GetOn.Value.Value == true then getOnScriptParent = player:WaitForChild("PlayerGui") getOnScriptParent.GetOnFrame:Destroy() game.Workspace.GetOn.Value.Value = false end end end)