Hello,
I have a question. This script below was working before (I guess, I'm not really sure anymore), but now it doesn't. I don't know why. It's supposed to work like this: When the player has sat, a GUI will pop up and once the player left the seat, it'll remove. Could anyone tell me why this script isn't working?
01 | local vehicleseat = script.Parent |
02 | local GUI = script.DeleteGUI |
03 |
04 | script.Parent.Changed:connect( function (property) |
05 | if property = = "Occupant" then |
06 | local humanoid = vehicleseat.Occupant |
07 | if humanoid then |
08 | GUI:clone().Parent = game.Players:GetPlayerfromcharacter(humanoid.Parent):WaitForChild( "PlayerGui" ) |
09 | else |
10 | game.Players:GetPlayerFromCharacter(humanoid.Parent).PlayerGui:Destroy() |
11 | end |
12 | end |
13 | end ) |
Thanks in advance.
You have made one wrong error, I'll rewrite the script and show you where you have gone wrong
01 | local vehicleseat = script.Parent |
02 | local GUI = script.DeleteGUI |
03 |
04 | script.Parent.Changed:connect( function (property) |
05 | if property = = "Occupant" then |
06 | local humanoid = vehicleseat.Occupant |
07 | if humanoid then |
08 | GUI:clone().Parent = game.Players:GetPlayerfromcharacter(humanoid.Parent):WaitForChild( "PlayerGui" ) |
09 | else |
10 | -- before, you were removing the playergui not the deletegui |
11 | game.Players:GetPlayerFromCharacter(humanoid.Parent).PlayerGui.DeleteGui.Destroy() |
12 | end |
13 | end |
14 | end ) |
Hope this helps! ~tantec
On line 8 you said GetPlayerfromcharacter
. Remember that capitalization matters. Change it to GetPlayerFromCharacter
like you have it on line 10.
Also connect
is deprecated. Change it to Connect
.
Hope this helps! :)