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

Why doesnt this delete the button when im far away enough?

Asked by 4 years ago

local script:

while true do
    wait(1)
if game.Players.LocalPlayer.PlayerGui.ScreenGui:FindFirstChild("mine button coal1") then
    print("found button")
if (game.Players.LocalPlayer.Character.HumanoidRootPart.Position - game.Workspace.ores.coal.coal1.Position).magnitude < 5 then
    print("should get deleted")
    game.Players.LocalPlayer.PlayerGui.ScreenGui:FindFirstChild("mine button coal1"):Destroy()
    print("deleted")
end
end
end

prints found button so there is an issue with magnitude line

0
If my answer does not help, you need to edit your question to explain what you are trying to accomplish with your code and what is actually happening. alphawolvess 1784 — 4y
1
Shouldn't it be > 5 (more than 5) instead? sleazel 1287 — 4y
0
it should ye but it didnt work when it was less than 5 Gameplayer365247v2 1055 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago

Your line of code checking magnitude will not allow you to do your desired task unless you are less than 5 studs away from the coal1.

You are using a less than sign when you, I assume based on the question, mean to use a greater than sign > meaning being farther than 5 studs from coal1.

I took it upon myself to add a player variable below:

local Plr = game.Players.LocalPlayer
while true do
    wait(1)
    if Plr.PlayerGui.ScreenGui:FindFirstChild("mine button coal1") then
            print("found button")
        if (Plr.Character.HumanoidRootPart.Position -                           game.Workspace.ores.coal.coal1.Position).magnitude > 5 then
                print("should get deleted")
                Plr.PlayerGui.ScreenGui:FindFirstChild("mine button coal1"):Destroy()
                print("deleted")
        end
    end
end
0
i had the right idea i just wrote wrong in my script but thanks for reminding me, ill accept anyway Gameplayer365247v2 1055 — 4y
Ad

Answer this question