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

How to make me a owner of a Throne Seat?

Asked by 2 years ago

i made a script that allow only me to sit in a Throne, its working, but i need to touch the seat like 3-5 times until i sit, it shows this until it work:

14:27:05.409 Workspace.BaragganThroneRemote.Seat.PermToSit:10: attempt to index nil with 'CharacterAdded' - Server - PermToSit:10

my script is this:

local allowed = {438845010}
local players = game:GetService("Players")
local seat = script.Parent

seat.Disabled = false

seat.Touched:Connect(function (hit)
    if seat.Occupant then return end
    local player = players:GetPlayerFromCharacter(hit.Parent)
    local Character = player.CharacterAdded:Wait()


    for i = 1, #allowed do
        if allowed[i] == player.UserId then
            local humanoid = player.Character:FindFirstChildWhichIsA("Humanoid")
            if humanoid then
                seat.Disabled = false
            end
        else 
            seat.Disabled = true
        end

    end
end)

wt am i doing wrong? can i do something that i just sit and its it, dont fail like 3 times until work?

2 answers

Log in to vote
0
Answered by 2 years ago
--LocalScript in StarterPlayerScripts
if game.Players.LocalPlayer.UserId==438845010 then
    workspace.Throne.Seat.Disabled=false
    end

--ServerScript:
--workspace.Throne.Seat.Disabled=true
Ad
Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

Create a Script inside of a Seat and paste this code inside of it. Make sure to type your name in the variable correctly.

local OwnerName = " Owner Name " -- Type Seat Owner's Name

script.Parent.ChildAdded:Connect(function(Part)
    if Part.Name == "SeatWeld" then
        if Part.Part1.Parent.Name == OwnerName then
            print("OwnerSitting")
        else
            wait(0.1)
            Part.Part1.Parent.Humanoid.Sit = false
        end
    end
end)

The script is much Shorter but is efficient.

Answer this question