Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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.

2 comments

0

To get workspace you can just do game.Workspace :)

0

Thanks... :l What part(s) in scripting should I learn to be able to do what I asked?

1 answer

✓ Accepted answer

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)

6 comments

0

Thanks, but can you explain to me what is happening in the script you wrote?

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.

1

Thanks, but I have one more more question. 1) When you say "child.part1" What is part1? Thanks for your help.

1

It is the part that is welded with the seat. (The player in this case)

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?

0

You can change the variable's name. He used the ChildAdded event.

This discussion is preserved as it was. New answers, comments, and votes are closed.