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.

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
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.

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)

Ad

Answer this question