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

[SOLVED] Owner-Only Seat is not working using Humanoid.Sit?

This is a plane seat. I basically want it that only the owner can fly it. Any help?

function touc(part)
	local plr = game.Players:FindFirstChild(part.Parent.Name)
	if plr then
		local h = part.Parent:FindFirstChild("Humanoid")
		if h then
			if part.Parent.Name ~= script.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Owner.Value.Character.Name then
				if h.Sit == true then
					h.Sit = false
					h.Jump = true
				else
					print("Nothing")
				end
		end
		end
	end
end
script.Parent.Touched:connect(touc)

1 answer

Update: totally rewrote the code after knowing how terrible it is. Still doesn't 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 name ~= script.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Owner.Value then
                repeat wait()
                Seat.Occupant.Sit = false
                until Seat.Occupant.Sit == false
            end
        end
    end
end)

2 comments

0

Error: attempt to index nil with 'Owner' -- line 8

0

Solved. I used this to detect the player: local player = game.Players:GetPlayerFromCharacter(Seat.Occupant.Parent)

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