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

Why is this piece of code in relation to a GUI not working?

local players = game:GetService("Players")


function onTouched(part)


local player = players:GetPlayerFromCharacter(part.Parent)
    ~~~~~~~~~~~~~~~~~

	if player then

		local abzx = player.PlayerGui.Objective1.Frame

		abzx:Destroy()

	end

end


script.Parent.Touched:connect(onTouched)

The intended purpose of this piece of code is to remove a GUI once a brick has been touched, I know there are some codes which allow me to do this but I want to understand the concept before utilizing it. I have checked the error log and nothing shows up in relevance to this script. Can anyone help me?

1 answer

function onTouched(part)
local player = game.Players:GetPlayerFromCharacter(part.Parent)
if part.Parent:findFirstChild("Humanoid") then
local abzx = player.PlayerGui.Objective1.Frame
abzx:Destroy()
end
end
script.Parent.Touched:connect(onTouched)

It should work :) I wish I helped You

1 comment

0

It does not work

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