Something not working with my player Seat?

So I have this script that should be making the player jump if they arn’t the player named in the child boolvalue. Any help here?

local accepted = script.OwnerName
function check(p)
if p.Character.Name == accepted then return true end
return false
end


script.Parent.ChildAdded:connect(function(child)
		if child:IsA("Weld") then
			if child.Part1 ~= nil then
				if child.Part1.Parent ~= nil then
					if game.Players:playerFromCharacter(child.Part1.Parent) ~= nil then
						


local player = game.Players:playerFromCharacter(child.Part1.Parent)
if check(player) then else child.Part1.Parent.Humanoid.Jump = true end

					end
				end
			end
		end
	end)

image

So two things,

  1. I’m going to change up your script a lot to make it better
  2. I’m going to assume that when you said boolvalue you actually meant string value since you said name, which should be a string
local PlayerService = game:GetService("Players") -- get playerservice
local OwnerName = script.OwnerName.Value -- define owner

script.Parent.Changed:Connect(function(newvalue) -- setup a function connected to the Changed event with a newvalue arg
    if newvalue ~= "Occupant" then return end -- make sure the change was an occupant
    local Player = PlayerService:GetPlayerFromCharacter(script.Parent.Occupant.Parent) -- get the player
    if not Player then return end -- check if player is nil (maybe an npc sat down idk)
    if Player.Name == OwnerName then -- check if its the owner
        --rest of code here
    else -- if it isn't
        script.Parent.Occupant.Jump = true -- make them jump
    end -- close if statement
end) -- close function

Okay so I tried and got an error at line 6?

`

local Player = PlayerService:GetPlayerFromCharacter(script.Parent.Occupant.Parent)

`

What was the error that you got?

Attempt to index field Occupant

image
Add right there

if not script.Parent.Occupant then return end

wait, the script is a child of the seat, yes?

Ahhh yes, this works, thank you so much for helping me out here.

1 Like

if you’re only checking for Occupant in that situation, then why not hook it to :GetPropertyChangedSignal(“Occupant”), that way you don’t get the un-necessary fires.

3 Likes