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

How to kill people if I sit in a seat if they are not the specified person sitting in the seat?

Asked by 10 years ago

I want to be able to have a string value with a player's name so that only that player can sit in a Seat object, if it is not the player then kill the person sitting in the chair

2 answers

Log in to vote
0
Answered by 10 years ago

I'm not sure if this is correct, you may need to double check this:

seat = SEAT PATH HERE
access = {"fahmisack123" , "fahmisack123", etc..}

function Check(Player) --Sets a function
    player = Player.Parent:FindfirstChild("Humanoid") --Checks if it's a character
        if player ~= nil and player.Name ~= #access then --If it IS a character AND has their name in the access table then...
            player.Health = 0 --...Kill
        end
end

while true do --So it happens many times, not only once
    seat.Touched:connect(Check) --Calls the function
    wait() --Makes sure Studio and the game doesn't crash
end

----------------------- PLEASE NOTE -----------------
THIS MAY NOT BE CORRECT AS I AM NOT A PERFECTLY GOOD SCRIPTER
-----------------------------------------------------
0
This did not help but I tried doing this. Path = game.Workspace.Thrones.Model.Model.Seat function Check(Player) Player = game.Players:FindFirstChild("EngravedDarkVoid", true) if Player == false then a = game.Players:GetPlayerFromCharacter("Humanoid") a:Destroy() end end if Path == true then Path.Touched:connect(Check) end wargod435 0 — 10y
0
I have run out of ideas, sorry. fahmisack123 385 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

This would be the best way to do it:

local Seat = SEAT_PATH_HERE
local Access = {"TurboFusion","wargod435",...}
function IsAccess(Player)
    for _,v in pairs(Access) do --Iterates through the Access table
        if string.lower(Player.Name) == string.lower(v) then --Checks to see if the player's name is in the table
            return true
        end
    end
    return false
end

Seat.ChildAdded:connect(function(Child) --This event fires whenever a child is added to the seat
    if Child.Name == "SeatWeld" then --If the child is a seatweld...
        local Player = game.Players:GetPlayerFromCharacter(Child.Part1.Parent) --Gets the player
        if Player then --If the player exists...
            if IsAccess(Player) then --Calls the IsAccess function and checks if it's true
                --Do stuff
            else --if it's false...
                Player.Character.Humanoid.Health = 0 --Kills the player
            end
        end
    end
end)

Hope this helped!

0
Thanks wargod435 0 — 10y

Answer this question