Hi, I am making a Tycoon and I am trying to script a door that when a player walks through the door, he dies but when the owner of the tycoon walks through it, he's fine. I have tried to script it but it won't work and when I touch to own the tycoon and by the Owner Only Door then walk through it, it kills me. Here is my script:
function onTouche() print(game.Players.LocalPlayer.Name) --Just checking if this line worked if game.Players.LocalPlayer.Name == script.Parent.Parent.Parent.Parent.Parent.Owner.Value then script.Parent.CanCollide = false else game.Players.LocalPlayer.Character.Humanoid.Health = 0 end end script.Parent.Touched:connect(onTouche)
Hello. I checked your code and you did something wrong over here
game.Players.LocalPlayer.Name doesn't exist.
Use game.Players.LocalPlayer instead.
And, too, you're not seeting cancollide back to true!
And it will be better if you call the function with a hit object, and don't use localplayer anyway. That gives back the client's username, so weird things may happen.
Here is the correct code:
function onTouch(hit) if hit.Parent.Name == script.Parent.Parent.Parent.Parent.Parent.Owner.Value then script.Parent.CanCollide = false -- Also, you're not setting cancollide back to true! wait (3) -- Customize it script.Parent.CanCollide = true else hit.Parent.Humanoid.Health = 0 end end script.Parent.Touched:connect(onTouch)
Anyway, I don't recommend making that. It's better to make this code and make the VIP door cancollide false and Anchored true, and if the owner passes, do nothing, but if it's not the owner, kill the character.
Here is my recommended code:
function onTouch(hit) if hit.Parent.Name == script.Parent.Parent.Parent.Parent.Parent.Owner.Value then else hit.Parent.Humanoid.Health = 0 end end script.Parent.Touched:connect(onTouch)
PD: Also, I recommend too to add a button that if you click it, this script disables, so that the tycoon owner can let friends in. But that's another story.
Hope it was usefull!