#BASIC SCRIPT HELP REQUEST

45 messages · Page 1 of 1 (latest)

undone urchin
#

send script

#

you can screenshot it

#

how long is it

glad gull
undone urchin
#

why do you wanna dm

glad gull
#

133 lines

#

here

#

lemme see if i can send it w/o file

undone urchin
#

it isnt too much

#

send it as a code block or something

glad gull
#

how do i do that

undone urchin
glad gull
#

i cant

undone urchin
glad gull
#

i had to do the file

undone urchin
#

send it in bits

glad gull
#

bits??

#

oh

undone urchin
#

small bits

glad gull
#

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

undone urchin
#

what does your script do

glad gull
#

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

glad gull
#

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

undone urchin
#

so the player can't move after they die

glad gull
#

the mobile player

#

pc players are fine, so its somethign with the way i did the gui buttons

undone urchin
#

did you make custom buttons

glad gull
#

yeah

#

its just a screen gui with a child of a button

#

its a text button

undone urchin
#

oh

glad gull
#

this is what i mean by axis

#

are you able to fix it atall?

@undone urchin

undone urchin
#

sorry

neat ginkgo
#

Make sure that the touch input connections for dragging the GUI elements are re-established whenever the player respawns.