Okay, so I have a wall that only allows certain teams to enter. I want the script to pop a message if the other team goes and touches the wall. The killing of the the other team works, and the transparency and everything works, but the message does not. Can someone help me with this? I only want the message going to that one person who was trying to go through that door/wall
Thanks here is what i have!
Door = script.Parent ------------------------------------ modelname="Taxi Driver" ------------------------------------ function onTouched(hit) print("Door Hit") local human = hit.Parent:FindFirstChild("Humanoid") local message = Instance.new("Message") message.Parent = game.Players:playerFromCharacter(hit.Parent) if (human ~= nil ) then if game.Players:playerFromCharacter(hit.Parent).TeamColor==game.Teams:findFirstChild(modelname).TeamColor then Door.Transparency = 1 wait(1) Door.CanCollide = false Door.Transparency = 1 else human.Health = 0 message.Text = "Player was not a Taxi Driver" wait(5) message:Remove () end end end connection = Door.Touched:connect(onTouched) local debounce = false
You're putting the message inside of Player. It needs to go inside of PlayerGui.
Door = script.Parent ------------------------------------ modelname="Taxi Driver" ------------------------------------ function onTouched(hit) print("Door Hit") local human = hit.Parent:FindFirstChild("Humanoid") local message = Instance.new("Message") message.Parent = game.Players:GetPlayerFromCharacter(hit.Parent).PlayerGui if (human ~= nil ) then if game.Players:playerFromCharacter(hit.Parent).TeamColor==game.Teams:findFirstChild(modelname).TeamColor then Door.Transparency = 1 wait(1) Door.CanCollide = false Door.Transparency = 1 else human.Health = 0 message.Text = "Player was not a Taxi Driver" wait(5) message:Remove () end end end connection = Door.Touched:connect(onTouched) local debounce = false
Problem
The message is not showing up.
Solution
You put the message in the player. You should put it in the PlayerGui to be client-sided.
Suggestions
playerFromCharacter
is deprecated, meaning it is unfavorable but still fully functional., use GetPlayerFromCharacter
. Also, remove the "connection" variable and just keep it as Door.Touched:connect(onTouched)
. :findFirstChild
was changed to capitalize to :FindFirstChild
. Local variables are also in favor to stop lag. You can also parent a new instance by adding it, like this: Instance.new("Part", workspace)
. And the debounce is not there in the beginning so I'll fix that. This is all very outdated.
Final Script (w/ Suggestions)
local Door = script.Parent debounce = false local modelname="Taxi Driver" function onTouched(hit) print("Door Hit") local human = hit.Parent:FindFirstChild("Humanoid") local message = Instance.new("Message", game.Players:GetPlayerFromCharacter(hit.Parent).PlayerGui) if (human ~= nil ) and (debounce == false) then if game.Players:GetPlayerFromCharacter(hit.Parent).TeamColor==game.Teams:FindFirstChild(modelname).TeamColor then debounce = true Door.Transparency = 1 wait(1) Door.CanCollide = false Door.Transparency = 1 else human.Health = 0 message.Text = "Player was not a Taxi Driver" wait(5) message:Remove() end end end Door.Touched:connect(onTouched) debounce = false
Remember if this helped, give me a thumbs up and hit that accept button! It helps us both!