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

How do I fix this script to remove the Gui when the player is not touching the part anymore?

In the output it states that attempt to call field 'TouchEnded' (a userdata value) if that helps and if possible >** put a script and explain what the script does so I can understand the script.**

script.Parent.TouchEnded(function(ended)
	local parent = ended.Parent
	local player = game.Players:GetPlayerFromCharacter(parent)
	
	if player then
		if player.PlayerGui:FindFistChild("TeleportGui") then
			player.PlayerGui.TeleportGui:Destroy()
		end
	end
end)

:)

1 answer

✓ Accepted answer

This should work. Let me know if it doesnt.

local touchPart = script.Parent
local deb = false

touchPart.TouchedEnded:connect(function(hit)

	if deb == false then deb = true
		if hit then
			local chr = hit.Parent
			local plr = game.Players:GetPlayerFromCharacter(chr)
			if plr.PlayerGui:FindFirstChild("TeleportGui") then
				plr.PlayerGui.TeleportGui:Remove()
			end
		end
	wait(1)
	deb = false
	end

end)

2 comments

0

Oops I put 'TouchedEnded' instead of 'TouchEnded' Just change that and you should be gucci

0

This isn't a big problem but what do they mean by attempt to index local 'plr' (a nil value)?

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