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

How can I make it so when you sit in a seat, if your username does not match a value, it jumps you?

Asked by 5 years ago
Edited 5 years ago

I am trying to make a booking system, and I am trying to make it so if you sit in a seat, and your username does not match the true owner of the seat (which the username of the true owner is in a string value), then it will jump you. I have tried with many attempts, but I have not succeeded. How do you go about this? My scripts are below. I have both the local script and standard script as a child of the seat.

-- Local Script
local Username = script.Parent.Parent:WaitForChild("Username")
local UsernameValue = Username.Value
script.Parent.ChildAdded:Connect(function()
    if script.Parent.Occupant.Parent.Name == UsernameValue then
        local donothing = game
    else
        script.Parent.KickOutOfSeat:FireServer()
    end
end)

-- Normal Script
script.Parent.KickOutOfSeat.OnServerEvent:Connect(function()
        script.Parent.SeatWeld:Destroy()
        script.Parent.SeatWeld:Destroy()
        script.Parent.SeatWeld:Destroy()
        script.Parent.SeatWeld:Destroy()
        script.Parent.SeatWeld:Destroy()
        script.Parent.SeatWeld:Destroy()
        script.Parent.SeatWeld:Destroy()
        script.Parent.SeatWeld:Destroy()
end)
0
This won't work ever is the problem, you simply can't use a localscript this way. SteamG00B 1633 — 5y
2
Also why do you hate the seat weld so much? SteamG00B 1633 — 5y

2 answers

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

Firstly, LocalScripts do not run in the Workspace unless they are descendant of a player's character, which is in the Workspace. They also run as descendants of the Backpack, PlayerGui, PlayerScripts, and ReplicatedFirst. Secondly, you do not need a remote event for this at all. You can listen for the Occupant property changing, with the :GetPropertyChangedSignal() method.

local seat = script.Parent

seat:GetPropertyChangedSignal("Occupant"):Connect(function()
    if seat.Occupant then -- if the occupant is there
        seat.Occupant.Jump = true
    end
end)

Finally, you do not need to call :Destroy() on an object 7 times. Once will suffice.


Hopefully this answered your question, and if it did, then don't forget to hit that "Accept Answer" button. If you have any other questions, then feel free to leave them down in the comments.
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago
--Local script

script.Parent:GetPropertyChangedSignal("Occupant"):Connect(function()
    local Username = script.Parent.Parent:WaitForChild("Username")
    if script.Parent.Occupant ~= Username.Value then
        script.Parent.KickOutOfSeat:FireServer()
    end
end)


--Server Script
script.Parent.KickOutOfSeat.OnServerEvent:Connect(function(plr)
    plr.Character.Humanoid.Jump = true
end)

I'd like to note that I can already tell that you're going to have problems running this. As the code implies, both the server script and the local script are children of the same remote event. You should know that local scripts cannot run in workspace, which is where I'm assuming it's located.

0
If you know `not` logic you will know that line 5 will fail. User#24403 69 — 5y
0
should be > if script.Parent.Occupant ~= Username.Value then SteamG00B 1633 — 5y
0
was accident, was typing fast Gey4Jesus69 2705 — 5y

Answer this question