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

player.Touched(function() doesnt even function, why? (nothing in output)

If something isnt defined or one of the ends is messed up Its probally fixed in my original script, I just had to make a script rn because I cant use roblox studio rn This localscript is in the part:

while wait(1) do
player.Touched(function()
StarterGui.Quest1.Frame.Visible = true
if player.Touched = false then
StarterGui.Quest1.Frame.Visible = false
end
end)

2 answers

✓ Accepted answer

This should work:

local part = script.Parent

part.Touched:Connect(function(hit)
	local plr = game.Players:GetPlayerFromCharacter(hit.Parent)

	if plr then
		plr:WaitForChild("PlayerGui").YouScreenGuiHere.Frame.Visible = true
	end
end)

1 comment

0

Though tweaking can be done, this is the correct answer ^^. I'll accept it for ya!

Here's my script, this binds the TouchEnded and Touched event which should help you understand Touch events a lot better.

local Players = game:GetService("Players")
local BasePart = (script.Parent:IsA("BasePart") and script.Parent) or script:FindFirstAncestorOfClass("BasePart")

BasePart.Touched:Connect(function(Hit)
	local Character = (Hit.Parent:IsA("Model") and Hit.Parent) or Hit:FindFirstAncestorOfClass("Model")
	pcall(function()
		local Player = Players:GetPlayerFromCharacter(Character)
		local PlayerGui = Player:FindFirstChildOfClass("PlayerGui")
		PlayerGui.Quest1.Frame.Visible = true
	end)
end)

BasePart.TouchEnded:Connect(function(Hit)
	local Character = (Hit.Parent:IsA("Model") and Hit.Parent) or Hit:FindFirstAncestorOfClass("Model")
	pcall(function()
		local Player = Players:GetPlayerFromCharacter(Character)
		local PlayerGui = Player:FindFirstChildOfClass("PlayerGui")
		PlayerGui.Quest1.Frame.Visible = false
	end)
end)

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