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

Magnitude doesn't seem to be working?

Asked by 4 years ago

Ok so I'm working on a small thing that uses magnitude. Basically in workspace there's a folder that contains parts which are all named the same thing however the parts are spread around the map. The local script gets the folder and checks whether the name of the part is "Hello," if the name is "Hello," then the local script makes a simple text label visible. Hope this kind of gives you an idea of what I'm trying to do.

while wait() do
    local checkPart = game.Workspace.Wow:GetChildren() --Folder in workspace
    if checkPart.Name == "Hello" then
    local dis = (game.Workspace.checkPart.Position - game.Players.LocalPlayer.Character.HumanoidRootPart.Position).magnitude
    if dis <= 10 then
        script.Parent.TextLabel.Visible = true
        wait()
    end
    if dis >= 9 then
        script.Parent.TextLabel.Visible = false
        wait()
    end
    wait()
    end
    wait()
    end
0
if you are waiting until the part is a certain distance from the player use "repeat; (code here); until <Boolean>".. Seems more of an >>XY problem<< as you can easily check if .magnitude works by printing it out. Sergio4755 21 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

I edited your script a bit the script is using "For loops" to loop throw all the parts in the folder and checks if the name is correct (hello) its not perfect but it will take me time to fix the Flashes (i know what is the problem)

while true do
    for i,v in pairs(game.Workspace.Wow:GetChildren()) do
        if v.Name == "Hello" then
            local dis = (v.Position - game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart").Position).magnitude
            if dis <= 10 then
                script.Parent.TextLabel.Visible = true
                wait()
            else 
                script.Parent.TextLabel.Visible = false
                wait()
            end
        end
    end
end 

ok finally I got the fixed version

local c
script.Parent.TextLabel.Visible = false
while true do
    for i,v in pairs(game.Workspace.Wow:GetChildren()) do
        wait()
        if v.Name == "Hello" then
            local dis = (v.Position - game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart").Position).magnitude
            if dis <= 10 then
                script.Parent.TextLabel.Visible = true
                wait()
                c = i
            else 
                if i == c then
                    script.Parent.TextLabel.Visible = false
                    wait()
                    local c = nil
                end
            end
        end
    end
end 

Ad

Answer this question