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

What part(s) of scripting should I learn for this?

Asked by 10 years ago

How do I make a script to where when a player sits on a Vehicle Seat GUI pops up on their screen? This is as far as I've gotten knowing what I know at the moment.

Workspace = script.Parent.Parent.Parent.Parent

function OnTouched(Player)
    if game.Players:GetPlayerFromCharacter(Workspace) then

    end
end

script.Parent.Touched:connect(OnTouched)

I don't know if this is all correct. If you could, tell me what part(s) in scripting I should learn so next time when I want to do something like this I know exactly what to do. Thanks

P.s. I'm not asking you to make it for me, i'm asking what part(s) in scripting I should learn so next time when I want to do something like this I know exactly what to do.

0
To get workspace you can just do game.Workspace :) YellowoTide 1992 — 10y
0
Thanks... :l What part(s) in scripting should I learn to be able to do what I asked? notes4u99 65 — 10y

1 answer

Log in to vote
1
Answered by 10 years ago

Place this script and the GUI inside the vehicle seat.

seat = script.Parent
s = script

function onChildAdded(child)
    if child.Name == "SeatWeld" then
        local human = child.part1.Parent:findFirstChild("Humanoid") 
        if (human ~= nil) then
            -- Replace GUI with the gui name
            s.GUI:clone().Parent = game.Players:findFirstChild(human.Parent.Name).PlayerGui
        end
    end
end

function onChildRemoved(child)
    if (child.Name == "SeatWeld") then  
        local human = child.part1.Parent:findFirstChild("Humanoid") 
        if (human ~= nil) then
    -- Replace GUI with the gui name
            game.Players:findFirstChild(human.Parent.Name).PlayerGui.GUI:remove()
        end
    end
end


script.Parent.ChildAdded:connect(onChildAdded)
script.Parent.ChildRemoved:connect(onChildRemoved)
0
Thanks, but can you explain to me what is happening in the script you wrote? notes4u99 65 — 10y
1
So when a player sits on the vehicle seat a "SeatWeld" is created. (A child is added) Then the GUI inside the vehicle seat is cloned and placed into the PlayerGui (making the GUI visible to the player). If the player leaves the seat the "SeatWeld" is removed and the GUI is deleted. ultimate055 150 — 10y
1
Thanks, but I have one more more question. 1) When you say "child.part1" What is part1? Thanks for your help. notes4u99 65 — 10y
1
It is the part that is welded with the seat. (The player in this case) ultimate055 150 — 10y
View all comments (2 more)
0
Sorry, but I got another question. When you said the function "onChildAdded(child)" How is child used in the function? Like when you say "if child.Name == "SeatWeld" then" What is child in this case? notes4u99 65 — 10y
0
You can change the variable's name. He used the ChildAdded event. Shawnyg 4330 — 10y
Ad

Answer this question