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

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

Asked by 4 years ago

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.

0
try changing the "if not player.Name == "iiPizzaCraver" then statement to "if player.Name ~= "iiPizzaCraver" then" ExHydraboy 30 — 4y
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" ExHydraboy 30 — 4y
0
Okay i will try it iiPizzaCraver 71 — 4y
0
Humanoid is not a vlid member of player iiPizzaCraver 71 — 4y
View all comments (10 more)
0
What have you defined player as ExHydraboy 30 — 4y
0
local player = game.Players:GetPlayerFromCharacter(newChild.Part1.Parent) iiPizzaCraver 71 — 4y
0
how did you implement the if statement on line 7 ExHydraboy 30 — 4y
0
the way you told me to do it iiPizzaCraver 71 — 4y
0
Try putting a bunch of print statements that print the values of the defined variables. That works like 99% of the time ExHydraboy 30 — 4y
0
idk how to do that iiPizzaCraver 71 — 4y
0
an example would be like print(player.Name) to see what the game's getting as the playername ExHydraboy 30 — 4y
0
Oh ok iiPizzaCraver 71 — 4y
0
lmk what you get as output ExHydraboy 30 — 4y
0
my name iiPizzaCraver 71 — 4y

1 answer

Log in to vote
1
Answered by
Mayk728 855 Moderation Voter
4 years ago
Edited 4 years ago

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)
0
That looks right. Sorry I was on mobile and am not able to test this in studio ExHydraboy 30 — 4y
0
that's fine. if it ends up working, don't forget to accept my answer. :) Mayk728 855 — 4y
1
Thank you very much! Sorry for the late response, been off studio for a little while. Much appreciated! iiPizzaCraver 71 — 4y
Ad

Answer this question