Hello! What I want is if a player has a ticket they can step on a part however if they don’t have a ticket I want it to kill the player. Is this possible?
Sure it’s possible. You can either create a value inside of the player or the character named “Ticket”, then check if there’s something called “Ticket” when the .Touched function activates, and if it returns nil then kill the humanoid.
Ok. This is my script inside a part. How would I go about not killing the player if they have the ticket?
function onTouched(hit)
if hit.Parent:findFirstChild("Humanoid") then
hit.Parent.Humanoid:TakeDamage(100)
end
end
Add an if statement checking if the character has something called “Ticket” inside of it:
function onTouched(hit)
if hit.Parent:findFirstChild("Humanoid") then
if hit.Parent:FindFirstChild("Ticket") then return end
hit.Parent.Humanoid:TakeDamage(100)
end
end
Wow thanks so much! I didn’t know it was that simple
Sorry I know I marked your answer as solution but it kills them if they don’t have the ticket equipped? Is it possible to make it if they have the item then it won’t kill them?
Yeah sure, if you want them to have the ticket then you can keep the code I gave you, but if you want them NOT to have the ticket then you can replace the 3rd line with:
if hit.Parent:FindFirstChild("Ticket") == nil then return end
Sorry that’s not what I meant. Basically if the player has a ticket in their inventory then they will not die when they touch the part even if the ticket is not equipped. If the player doesn’t have any ticket in their inventory then they will die when they touch the part. Sorry for the confusion.
Oh you mean in the backpack? -------
Yes. If they have a ticket in their backpack then they will not die when touching the part. Sorry I think I explained it badly.
No problem mate. Then, you can retrieve the player’s backpack and check if they have something called ticket inside of it instead of the character. To retrieve the player from a character, you can use :GetPlayerFromCharacter()
function onTouched(hit)
if hit.Parent:findFirstChild("Humanoid") then
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
if (Player and Player.Backpack:FindFirstChild("Ticket")) or hit.Parent:FindFirstChild("Ticket") then return end
hit.Parent.Humanoid:TakeDamage(100)
end
end
Even if they don’t have a ticket equipped, then they won’t die as the function returns if a ticket is found in the backpack (not equipped) or the character (equipped).
Thank you so much! This is what I was looking for!