Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I want to constantly check if the player is inside the area. Code stops when it checks.?

Asked by
Avoxea 48
5 years ago

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.

01player = game.Players.LocalPlayer
02    repeat wait() until player:HasAppearanceLoaded() == true
03    while true do
04        wait()
05    local magnitude = (player.Character.UpperTorso.Position - game.Workspace.GetOn.Position).magnitude
06    print(magnitude)
07    if magnitude <9.9 then
08        if player and script.Parent.getOnScriptMoved.Value == false then
09        getOnScript = game.ServerStorage.GetOnFrame:Clone()
10        getOnScript.Parent = player:WaitForChild("PlayerGui")
11        wait()
12        script.Parent.getOnScriptMoved.Value = true
13    end
14    elseif magnitude >10 then
15        guiLocation = player:WaitForChild("PlayerGui")
16        if guiLocation.GetOnFrame then
17            guiLocation.GetOnFrame:Destroy()
18        end
19    end
20    end
0
"repeat wait() until player:HasAppearanceLoaded() == true", player.CharacterAppearanceLoaded:Wait() exists you know, don't reinvent the wheel User#24403 69 — 5y

1 answer

Log in to vote
0
Answered by
Avoxea 48
5 years ago

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.

01player = game.Players.LocalPlayer
02    repeat wait() until player:HasAppearanceLoaded() == true
03        wait()
04game.Workspace.GetOn.Touched:Connect(function()
05    local magnitude = (player.Character.UpperTorso.Position - game.Workspace.GetOn.Position).magnitude
06        if magnitude <9.9 and game.Workspace.GetOn.Value.Value == false then
07        wait()
08            if player and game.Workspace.GetOn.Value.Value == false then
09             getOnScript = game.Workspace.GetOnFrame:Clone()
10             getOnScript.Parent = player:WaitForChild("PlayerGui")
11             wait()
12             game.Workspace.GetOn.Value.Value = true
13            end
14        end
15end)
01player = game.Players.LocalPlayer
02    repeat wait() until player:HasAppearanceLoaded() == true
03        wait()
04game.Workspace.Baseplate.Touched:Connect(function()
05    local magnitude = (player.Character.UpperTorso.Position - game.Workspace.GetOn.Position).magnitude
06        if magnitude >9.9 and game.Workspace.GetOn.Value.Value == true then
07        wait()
08            if player and game.Workspace.GetOn.Value.Value == true then
09             getOnScriptParent = player:WaitForChild("PlayerGui")
10             getOnScriptParent.GetOnFrame:Destroy()
11             game.Workspace.GetOn.Value.Value = false
12            end
13        end
14end)
Ad

Answer this question