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

Tycoon owner only door kills owner on touch?

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)

5 comments

0

you spelt on touch wrong

0

That;s not the problem, the ontouched function works fine, and that is just the name of the function.

0

The problem is it kills ME when I touch it (owner of tycoon, I don't want it to kill owner of tycoon, I dunno what did wrong)

0

Yup. Anyway, I posted an answer. Hope it works, because I didn't checked in Studio xD

0

Both codes do not work, they still kill the owner of tycoon. Also, when I printed out "game.Players.LocalPlayer.Name" it did work and printed out my name, I don't know what is wrong with the script.

1 answer

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!

2 comments

0

Both of the scripts also killed me again

0

Hummm... Are you sure of that the owner value is a string and it contents the user's username? And are you sure of that those parents are referencing to a string value, unique per door? What does the output say? Or it says nothing?

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