Alright so in these two scripts, first this ismore like for PC:
local TweenService = game:GetService("TweenService")
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local player = game.Players.LocalPlayer
local camera = game.Workspace.CurrentCamera
local roundStartPart = workspace:WaitForChild("RoundStartPart")
local playerGui = player:WaitForChild("PlayerGui")
local wasdGui = playerGui:WaitForChild("WASDGui")
-- Desired camera offset
local cameraOffset = Vector3.new(0, 25, 10) -- Adjust these values as needed
-- Flag to check if the round has started
local roundStarted = false
-- Re-enforce the humanoid WalkSpeed to 0
local moveStep = 4 -- The size of each step, adjust to fit the size of your blocks
local debounce = false
-- Function to lock the camera
local function lockCamera()
if player.Character then
local character = player.Character
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
local cameraPosition = humanoidRootPart.Position + cameraOffset
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = CFrame.new(cameraPosition, humanoidRootPart.Position)
end
end
-- Function to move the character with a jump effect
local function moveCharacter(direction)
if debounce then return end
debounce = true
local character = player.Character
if not character then return end
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
local humanoid = character:WaitForChild("Humanoid")
-- Ensure the character is grounded before moving
if humanoid.FloorMaterial == Enum.Material.Air then
debounce = false
return
end
-- Calculate the new position and orientation
local newPosition
local newLookVector
if direction == "Forward" then
newPosition = humanoidRootPart.Position + Vector3.new(0, 0, -moveStep)
newLookVector = Vector3.new(0, 0, -1)
elseif direction == "Backward" then
newPosition = humanoidRootPart.Position + Vector3.new(0, 0, moveStep)
newLookVector = Vector3.new(0, 0, 1)
elseif direction == "Left" then
newPosition = humanoidRootPart.Position + Vector3.new(-moveStep, 0, 0)
newLookVector = Vector3.new(-1, 0, 0)
elseif direction == "Right" then
newPosition = humanoidRootPart.Position + Vector3.new(moveStep, 0, 0)
newLookVector = Vector3.new(1, 0, 0)
end
-- Ensure the character stays upright and doesn't rotate unintentionally
newPosition = Vector3.new(newPosition.X, humanoidRootPart.Position.Y, newPosition.Z)
local targetCFrame = CFrame.new(newPosition, newPosition + newLookVector)
-- Tween for jump effect
local tweenInfo = TweenInfo.new(0.03, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
local jumpUp = TweenService:Create(humanoidRootPart, tweenInfo, {CFrame = humanoidRootPart.CFrame * CFrame.new(0, 5, 0)})
local jumpDown = TweenService:Create(humanoidRootPart, tweenInfo, {CFrame = targetCFrame})
-- Play the jump animation and move
jumpUp:Play()
jumpUp.Completed:Connect(function()
jumpDown:Play()
jumpDown.Completed:Connect(function()
wait(0.03) -- 0.1-second delay before allowing the next move
debounce = false
end)
end)
end
-- Function to handle player movement
local function handleMovement()
if player.Character then
local humanoid = player.Character:WaitForChild("Humanoid")
humanoid.WalkSpeed = 0 -- Ensure the character does not walk
-- Movement direction based on key pressed
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed or not roundStarted then return end
if input.KeyCode == Enum.KeyCode.W then
moveCharacter("Forward")
elseif input.KeyCode == Enum.KeyCode.A then
moveCharacter("Left")
elseif input.KeyCode == Enum.KeyCode.S then
moveCharacter("Backward")
elseif input.KeyCode == Enum.KeyCode.D then
moveCharacter("Right")
end
end)
end
end
-- Connect the touch event
roundStartPart.Touched:Connect(function(hit)
local touchedPlayer = game.Players:GetPlayerFromCharacter(hit.Parent)
if touchedPlayer and touchedPlayer == player and not roundStarted then
roundStarted = true
RunService.RenderStepped:Connect(lockCamera)
handleMovement()
-- Disable mobile controls and show WASD GUI
wasdGui.Enabled = true -- Show WASD GUI
end
end)
so what this do is that it locks camera on certain position, u cannot look anywhere, and also, instead of moving normally, when u press WASD it jumps. and yes That is located at started player scripts and works when touched a part called “RoundStartPart”
and i need to also do with mobile:
local TweenService = game:GetService("TweenService")
local player = game.Players.LocalPlayer
local gui = player:WaitForChild("PlayerGui"):WaitForChild("WASDGui")
local moveStep = 4 -- The size of each step, adjust to fit the size of your blocks
local debounce = false
local function moveCharacter(direction)
if debounce then return end
debounce = true
local character = player.Character
if character then
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
local humanoid = character:WaitForChild("Humanoid")
-- Calculate the new position and orientation
local newPosition
local newLookVector
if direction == "Forward" then
newPosition = humanoidRootPart.Position + Vector3.new(0, 0, -moveStep)
newLookVector = Vector3.new(0, 0, -1)
elseif direction == "Backward" then
newPosition = humanoidRootPart.Position + Vector3.new(0, 0, moveStep)
newLookVector = Vector3.new(0, 0, 1)
elseif direction == "Left" then
newPosition = humanoidRootPart.Position + Vector3.new(-moveStep, 0, 0)
newLookVector = Vector3.new(-1, 0, 0)
elseif direction == "Right" then
newPosition = humanoidRootPart.Position + Vector3.new(moveStep, 0, 0)
newLookVector = Vector3.new(1, 0, 0)
end
-- Ensure the character stays upright and doesn't rotate unintentionally
newPosition = Vector3.new(newPosition.X, humanoidRootPart.Position.Y, newPosition.Z)
local targetCFrame = CFrame.new(newPosition, newPosition + newLookVector)
-- Tween for jump effect
local tweenInfo = TweenInfo.new(0.03, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
local jumpUp = TweenService:Create(humanoidRootPart, tweenInfo, {CFrame = humanoidRootPart.CFrame * CFrame.new(0, 5, 0)})
local jumpDown = TweenService:Create(humanoidRootPart, tweenInfo, {CFrame = targetCFrame})
-- Play the jump animation and move
jumpUp:Play()
jumpUp.Completed:Connect(function()
jumpDown:Play()
jumpDown.Completed:Connect(function()
wait(0.03) -- 0.1-second delay before allowing the next move
debounce = false
end)
end)
end
end
gui.WButton.MouseButton1Click:Connect(function()
moveCharacter("Forward")
end)
gui.AButton.MouseButton1Click:Connect(function()
moveCharacter("Left")
end)
gui.SButton.MouseButton1Click:Connect(function()
moveCharacter("Backward")
end)
gui.DButton.MouseButton1Click:Connect(function()
moveCharacter("Right")
end)
this both almost do the same, this lower one just do for gui buttons and makes the mobile thumbstick lose functionality, but anyways, these both script only opperate once it touches the part I said “RoundStartPart” and the thing is i want to have another part lets call it “EndPart” which is a part that when touched, everything goes back to default, like the movement willl go back to walking instead of jumping forward, then camera that was locked will be free again, the functionality of mobile thumbstick and movement comes back, but then when it touches the “RoundStartPart” just loops. Can anyone help me? :3