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

Why the word this is a not working? please help this is making me loss brain cells

local Ready = true

local ReadyDo = true

script.Parent.Touched:Connect(function(hit)

if(hit)then

local H = hit.Parent:FindFirstChild("Humanoid")

if H ~= nil and Ready == true then

Ready = false

local plyr = game.Players:FindFirstChild(H.Parent.Name)

plyr.PlayerGui.ExitRed.Enabled = true

	hit.Parent.HumanoidRootPart.CFrame = CFrame.new(33.162, 8.374, 53.93)

end

end

end)

also its not the script that is wrong it is my door not working after the first time so I don't know if it has anything to do with my script thank you and ya

1 answer

✓ Accepted answer

The problem I see with your code is...You never set "ready" back to true after it is set to false and you need to use a remote event to enable that gui

Here are a few changes I made to your code

local ready = true

script.Parent.Touched:Connect(function(hit)
	--no need to check for hit, this function will never run if something does not "hit" the brick
	
	--want to avoid trying to find something by its name if you can, instead look for the humanoid class
	local H = hit.Parent:FindFirstChildOfClass("Humanoid")

	--when checking if something exists, there is not need to do ~= nil
	if H and ready == true then
		ready = false

		--Should use this instead of trying to find the player by name(more reliable)
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)

		---to mess with gui elements you need to use remote events/functions
		game.ReplicatedStorage.RemoteEvent:FireClient(player)
		--------------------------

		--You want to increase the Y position of where you teleport to player, otherwise they will teleport into a brick
		hit.Parent.HumanoidRootPart.CFrame = CFrame.new(33.162, 8.374, 53.93) + Vector3.new(0,3,0)

		wait(2)
		ready = true
	end
end)

1 comment

0

thanks!

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