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)
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.
--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.