Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

GUI pops up when player has sat. VehicleSeat.Occupant not working?

Asked by
snewo12 72
5 years ago

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?

local vehicleseat = script.Parent
local GUI = script.DeleteGUI

script.Parent.Changed:connect(function(property)
    if property == "Occupant" then 
        local humanoid = vehicleseat.Occupant
        if humanoid then
        GUI:clone().Parent = game.Players:GetPlayerfromcharacter(humanoid.Parent):WaitForChild("PlayerGui")
    else
        game.Players:GetPlayerFromCharacter(humanoid.Parent).PlayerGui:Destroy()
    end
    end
end)

Thanks in advance.

2 answers

Log in to vote
1
Answered by
tantec 305 Moderation Voter
5 years ago

You have made one wrong error, I'll rewrite the script and show you where you have gone wrong

local vehicleseat = script.Parent
local GUI = script.DeleteGUI

script.Parent.Changed:connect(function(property)
    if property == "Occupant" then 
        local humanoid = vehicleseat.Occupant
        if humanoid then
         GUI:clone().Parent = game.Players:GetPlayerfromcharacter(humanoid.Parent):WaitForChild("PlayerGui")
    else
    -- before, you were removing the playergui not the deletegui
        game.Players:GetPlayerFromCharacter(humanoid.Parent).PlayerGui.DeleteGui.Destroy()
    end
    end
end)

Hope this helps! ~tantec

0
i forgot to add :Destroy() btw tantec 305 — 5y
0
Oh wow!! I was probably too fast! But now I have this problem: http://prntscr.com/kl5yyn (attempt to index local 'humanoid' (a nil value)). When is stands up, the GUI doesn't delete as the script couldn't find the player again. How do I fix that? snewo12 72 — 5y
0
Nvm! Fixed everything! Thank you tantec :) snewo12 72 — 5y
Ad
Log in to vote
0
Answered by
chomboghai 2044 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

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! :)

0
It didn't work too :( snewo12 72 — 5y

Answer this question