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

Why is my seat not kicking out a foreign player?

Asked by 8 years ago

This script is supposed to kick out a player that has not bought the helicopter. But it didnt do so when I tested it out. Any ideas?

-RadioactiveSherbet

local pn = script.Parent.Parent.PlayerData.PlayerName.Value
local seat = script.Parent
seat.Changed:connect(function(property)
    if property ~= 'Occupant' then return end

    local occupant = seat.Occupant
    if occupant then
        local character = occupant.Parent
        local player = game.Players:GetPlayerFromCharacter(character)
        if player.Name == pn  then
        else
            character.Humanoid.Jump = true
            character.Humanoid.Jump = false

        end
    else
        print("Someone left the seat")
    end
end)

1 answer

Log in to vote
0
Answered by 8 years ago

Hello! i don't get why you're adding more scripts that there is a really simple solution to do this so here it is!

Example:

i put the script inside the Seat/Vehicle Seat and i added a Object inside on the seat it is a *"StringValue" *so this is where the player name will be assigned to after u bought it.

seat = script.Parent -- the Seat/Vehicle Seat
owner = script.Parent.Owner --The Name of the StringValue!

seat.Changed:connect(function()
      local occupant = seat.Occupant
    if occupant then -- Checks if there is an occupant!
         if owner.Value == occupant.Parent.Name then -- Checks if the value of the String is correct to the name of the Parent of the occupant!
            print("It's an owner") -- If it is Prints Owner!
          else
            print("It's not an owner") --if not Prints Not!
            wait(0.5) -- By not having this to wait it will crash your roblox studio because it will not calculate if the player is seated or not and tries to disabled it.
             seat.Disabled = true -- this will disable the seat to the player tries to seat it
            wait(1)
             seat.Disabled = false -- after a second it will re-enabled!
        end
    end
end)

If this helps please accept this Answer! it would help me and other people too :)

Ad

Answer this question