#BASIC SCRIPT HELP REQUEST
45 messages · Page 1 of 1 (latest)
ill dm you
133 lines isnt much
it isnt too much
send it as a code block or something
how do i do that
search it up
i had to do the file
send it in bits
small bits
ok
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
local cameraPart = workspace:WaitForChild("Cam-Part")
local axis = Vector3.new(1, 0, 0)
local moveDirection = Vector3.new(0, 0, 0)
local movingLeft = false
local movingRight = false
local function getMidpoint()
local totalPosition = Vector3.new(0, 0, 0)
local playerCount = 0
for _, player in pairs(Players:GetPlayers()) do
if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
totalPosition = totalPosition + player.Character.HumanoidRootPart.Position
playerCount = playerCount + 1
end
end
if playerCount > 0 then
return totalPosition / playerCount
else
return Vector3.new(0, 0, 0)
end
end
local function adjustCamera()
local midpoint = getMidpoint()
local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = CFrame.new(cameraPart.Position, midpoint)
end
PART 1
what does your script do
local function movePlayer(input, gameProcessedEvent)
if not gameProcessedEvent and input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.D then
moveDirection = axis
movingRight = true
elseif input.KeyCode == Enum.KeyCode.A then
moveDirection = -axis
movingLeft = true
end
end
end
local function stopMoving(input, gameProcessedEvent)
if not gameProcessedEvent and input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.D then
movingRight = false
if not movingLeft then
moveDirection = Vector3.new(0, 0, 0)
else
moveDirection = -axis
end
elseif input.KeyCode == Enum.KeyCode.A then
movingLeft = false
if not movingRight then
moveDirection = Vector3.new(0, 0, 0)
else
moveDirection = axis
end
end
end
end
local leftButton = player.PlayerGui.MobileButtons:WaitForChild("Right")
local rightButton = player.PlayerGui.MobileButtons:WaitForChild("Left")
local function onMobileButtonPressed(direction)
if direction == "left" then
movingLeft = not movingLeft
moveDirection = movingLeft and axis or Vector3.new(0, 0, 0)
elseif direction == "right" then
movingRight = not movingRight
moveDirection = movingRight and -axis or Vector3.new(0, 0, 0)
end
end
leftButton.MouseButton1Down:Connect(function() onMobileButtonPressed("left") end)
rightButton.MouseButton1Down:Connect(function() onMobileButtonPressed("right") end)
-- Handle player movement inputs
UserInputService.InputBegan:Connect(movePlayer)
UserInputService.InputEnded:Connect(stopMoving)
RunService.RenderStepped:Connect(function()
adjustCamera()
humanoid:Move(moveDirection, true)
PART 2
its just an axis movement script, where the player moves back and forth one a single axis, kind of like mortal kombat
if moveDirection.Magnitude > 0 then
humanoidRootPart.CFrame = CFrame.new(humanoidRootPart.Position, humanoidRootPart.Position - moveDirection)
end
end)
RunService.RenderStepped:Connect(function()
if humanoidRootPart then
local position = humanoidRootPart.Position
humanoidRootPart.CFrame = CFrame.new(position.X, position.Y, 0)
end
end)
local function onCharacterAdded(newCharacter)
humanoid = newCharacter:WaitForChild("Humanoid")
humanoidRootPart = newCharacter:WaitForChild("HumanoidRootPart")
-- Reset movement direction on respawn
moveDirection = Vector3.new(0, 0, 0)
movingLeft = false
movingRight = false
adjustCamera()
end
player.CharacterAdded:Connect(onCharacterAdded)
LAST PART
so the player can't move after they die
the mobile player
pc players are fine, so its somethign with the way i did the gui buttons
did you make custom buttons
oh
i dont think so
sorry
Make sure that the touch input connections for dragging the GUI elements are re-established whenever the player respawns.