New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

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

Asked by 3 months 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 1699 — 3mo
1
Shouldn't it be > 5 (more than 5) instead? sleazel 679 — 3mo
0
it should ye but it didnt work when it was less than 5 Gameplayer365247v2 729 — 3mo

1 answer

Log in to vote
1
Answered by 3 months 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 729 — 3mo
Ad

Answer this question