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

How can I make this door script to OnClick and NOT OnTouched?

I am making a door where only the group owner can make the door open and close. I want the door to be OnClicked and not OnTouched. How can I also make it so that when I click the door again, the door closes and goes back to Transparency = 1 CanCollide = true?

GroupId = 3348123

script.Parent.Touched:connect(function(hit)
	local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
	if plr:IsInGroup(GroupId) then
		script.Parent.Transparency = 1
		script.Parent.CanCollide = false
	end
end)

Please help me, thank you!

1 comment

0

Are you using a brick or a gui?

2 answers

Instead of doing .Touch, try .ClickDetector.MouseClick. Link to Roblox Wiki

3 comments

0

Says Workspace.Part.Script:5: attempt to index local 'plr' (a nil value). And what about my second question about making the door close (Transparency = 0; CanCollide = true)?

0

Did you add ClickDetector to the part?

0

Yes

Here you go. This is a part with a ClickDetector inside it. (the script is in the part).

script.Parent.ClickDetector.MouseClick:Connect(function(p)
	if p:IsInGroup(3348123) then
		script.Parent.Transparency = 1
		script.Parent.CanCollide = false
	end
end)

1 comment

0

How do I make it when I click again to close the door it goes back to Transparency = 0 and CanCollide = true?

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