Advertisement
OnFireRobloxScriptin

Press Button to Eject Player From Seat

Jan 13th, 2024
513
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.97 KB | None | 0 0
  1. --Script under the Seat
  2.  
  3. --//Variables
  4. local prox = script.Parent --Variable for the proximity prompt
  5. local seat = prox.Parent --Variable for the seat
  6. local eject = game.ReplicatedStorage:WaitForChild("Eject") --Variable for the Remote Event
  7.  
  8. --//Seat Check
  9. seat:GetPropertyChangedSignal("Occupant"):Connect(function() --When Seat status is changed
  10.     if seat.Occupant then --If someone is on the seat
  11.         prox.Enabled = false --Disable the proximity prompt
  12.     else --Any other scenario
  13.         prox.Enabled = true --Show the proximity prompt
  14.         seat.Disabled = true --Disable the seat
  15.     end
  16. end)
  17.  
  18. --//Sit on Seat
  19. prox.Triggered:Connect(function(player) --When the proximity prompt is triggered
  20.     local hum = player.Character:WaitForChild("Humanoid") --Variable for the player's humanoid
  21.     seat.Disabled = false --Disable the seat
  22.     seat:Sit(hum) --Sit the player on the seat
  23.     hum.JumpPower = 0 --Remove their ability to jump out of the seat
  24.     eject:FireClient(player) --Fire the Remote Event
  25. end)
  26.  
  27. --//Restore JumpPower
  28. eject.OnServerEvent:Connect(function(player) --When we recieve the Remote Event from the client
  29.     local hum = player.Character:WaitForChild("Humanoid") --Find the humanoid
  30.     hum.Sit = false
  31.     hum.JumpPower = 50 --Restor their ability to jump
  32. end)
  33.  
  34. --(different script) LocalScript under button
  35. --//Variables
  36. local player = game.Players.LocalPlayer --Variable for the player
  37. local hum = player.Character:WaitForChild("Humanoid") --Variable for the humanoid
  38. local eject = game.ReplicatedStorage:WaitForChild("Eject") --Variable for the Remote Event
  39.  
  40. --//Show Button
  41. eject.OnClientEvent:Connect(function() --When we recieve the Remote Event from the server
  42.     script.Parent.Visible = true --Show the button (make it visible)
  43. end)
  44.  
  45. --//Eject Player
  46. script.Parent.MouseButton1Click:Connect(function() --When the button is clicked
  47.     script.Parent.Visible = false --Hide the button (make it invisible)
  48.     eject:FireServer(player) --Fire the Remote Event back to the server
  49. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement