Advertisement
Mryeetmemes

ControlScript

May 24th, 2024
489
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.09 KB | None | 0 0
  1. local player = game.Players.LocalPlayer
  2. local UserInputService = game:GetService("UserInputService")
  3. local ContextActionService = game:GetService("ContextActionService")
  4.  
  5. local doJump = false
  6. local reviving = false
  7. local characterWalkSpeed = 40
  8.  
  9. game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Chat, false)
  10. game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Health, false)
  11. game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
  12.  
  13. player:WaitForChild("PlayerGui")
  14.  
  15. local function jump()
  16.     if player.Character ~= nil then
  17.         if player.Character.Humanoid.WalkSpeed == 0 then
  18.             -- Character is not yet moving, start screen was shown
  19.             doJump = false
  20.             if player.PlayerGui.StartScreen.StartInstructions.Visible == true then
  21.                 player.PlayerGui.StartScreen:Destroy()
  22.                 player.Character.Humanoid.WalkSpeed = characterWalkSpeed
  23.                 game.ReplicatedStorage.RemoteEvents.RunStarting:FireServer()
  24.             end
  25.         else
  26.             player.Character.Humanoid.Jump = true
  27.         end
  28.     end
  29. end
  30.  
  31. -- Handles behaviours
  32. local function characterTouchedBrick(partTouched)
  33.     local behaviours = partTouched:FindFirstChild("Behaviours")
  34.     if behaviours ~= nil then
  35.         behaviours = behaviours:GetChildren()
  36.         for i = 1, #behaviours do
  37.             if behaviours[i].Value == true then
  38.                 game.ReplicatedStorage.RemoteEvents.ExecuteBehaviour:FireServer(player.Character, partTouched, behaviours[i].Name)
  39.             end
  40.         end
  41.     end
  42. end
  43.  
  44. function characterAdded(newCharacter)
  45.     local humanoid = newCharacter:WaitForChild("Humanoid")
  46.     humanoid.WalkSpeed = 0
  47.     humanoid.Touched:connect(characterTouchedBrick)
  48.  
  49.     local splashScreen = player.PlayerGui:WaitForChild("StartScreen")
  50.  
  51.     if UserInputService.TouchEnabled == false then
  52.         if UserInputService.GamepadEnabled then
  53.             splashScreen.StartInstructions.StartLabel.Text = "Press Space or Gamepad A Button to Start"
  54.         else
  55.             splashScreen.StartInstructions.StartLabel.Text = "Press Space to Start"
  56.         end
  57.  
  58.     end
  59.     if reviving == true then
  60.         reviving = false
  61.         splashScreen:Destroy()
  62.         humanoid.WalkSpeed = characterWalkSpeed
  63.     end
  64.  
  65.     humanoid.WalkSpeed = 0
  66. end
  67. player.CharacterAdded:connect(characterAdded)
  68.  
  69. if player.Character then
  70.     characterAdded(player.Character)
  71. end
  72.  
  73. function checkReviving(addedGui)
  74.     if addedGui.Name == "RevivingGUI" then
  75.         reviving = true
  76.     end
  77. end
  78. player.PlayerGui.ChildAdded:connect(checkReviving)
  79.  
  80. if UserInputService.TouchEnabled then
  81.     UserInputService.ModalEnabled = true
  82.     UserInputService.TouchStarted:connect(function(inputObject, gameProcessedEvent) if gameProcessedEvent == false then doJump = true end end)
  83.     UserInputService.TouchEnded:connect(function() doJump = false end)
  84. else
  85.     ContextActionService:BindAction("Jump", function(action, userInputState, inputObject) doJump = (userInputState == Enum.UserInputState.Begin) end, false, Enum.KeyCode.Space, Enum.KeyCode.ButtonA)
  86. end
  87.  
  88. game:GetService("RunService").RenderStepped:connect(function()
  89.     if player.Character ~= nil then
  90.         if player.Character:FindFirstChild("Humanoid") then
  91.             if doJump == true then
  92.                 jump()
  93.             end
  94.             player.Character.Humanoid:Move(Vector3.new(0,0,-1), false)
  95.         end
  96.     end
  97. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement