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

How can I make it so that only a certain player can sit on a seat?

I want to make a seat exclusively for one player, if another player sits on it then they are forced to stand up (basically they can't sit down).

This is my script:

local seat = script.Parent
seat.ChildAdded:connect(function( newChild )	
	if newChild:IsA("Weld") then
		if newChild.Part1.Name == "HumanoidRootPart" then
			local player = game.Players:GetPlayerFromCharacter(newChild.Part1.Parent)
			if (player) then
				if not player.Name == "iiPizzaCraver" then
				player.Humanoid.Jump = true
					else
					--let them sit
				end
			end
		end
	end
end)

There are no errors in the output. It just doesn't work at all.

14 comments

0

try changing the "if not player.Name == "iiPizzaCraver" then statement to "if player.Name ~= "iiPizzaCraver" then"

0

beacuse it seems like that if statement is testing to see if there's a Instance named player.Name instead of testing to see if the value equates to "iiPizzaCraver"

0

Okay i will try it

0

Humanoid is not a vlid member of player

0

What have you defined player as

0

local player = game.Players:GetPlayerFromCharacter(newChild.Part1.Parent)

0

how did you implement the if statement on line 7

0

the way you told me to do it

0

Try putting a bunch of print statements that print the values of the defined variables. That works like 99% of the time

0

idk how to do that

0

an example would be like print(player.Name) to see what the game's getting as the playername

0

Oh ok

0

lmk what you get as output

0

my name

1 answer

✓ Accepted answer

had to test this myself in studio, but this should work.

local Players = game:GetService('Players')
local Seat = script.Parent

Seat.Changed:Connect(function()
	if Seat.Occupant ~= nil then
		--Seat.Occupant is the Humanoid
		local name = Seat.Occupant.Parent.Name
		if Players:FindFirstChild(name) then
			--if the name is NOT "iiPizzaCraver", then kick them off
			-- "~=" means not equal to
			if name ~= 'iiPizzaCraver' then
				repeat wait()
				Seat.Occupant.Sit = false
				until Seat.Occupant.Sit == false
			end
		end
	end
end)

3 comments

0

That looks right. Sorry I was on mobile and am not able to test this in studio

0

that's fine. if it ends up working, don't forget to accept my answer. :)

1

Thank you very much! Sorry for the late response, been off studio for a little while. Much appreciated!

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