Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

3 comments

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.

1

Shouldn't it be > 5 (more than 5) instead?

0

it should ye but it didnt work when it was less than 5

1 answer

✓ Accepted answer

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

1 comment

0

i had the right idea i just wrote wrong in my script but thanks for reminding me, ill accept anyway

This discussion is preserved as it was. New answers, comments, and votes are closed.