You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
im trying to make a movement script for mobile basically player touches a part of the screen and the player moves
What is the issue? Include screenshots / videos if possible!
im not having any errors i juat wanna know if i can use TouchStarted and TouchEnded but it only happens when i touch on certain part of the screen
here shows where i want to touch to make player move
and here is the explorer view
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
yes but no hope
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
local UserInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local function touchStarted(input, gameProcessed)
player:Move(Vector3.new(1,0,0))
end
local function touchEnded(input, gameProcessed)
player:Move(Vector3.new(0,0,0))
end
UserInputService.TouchStarted:Connect(touchStarted)
UserInputService.TouchEnded:Connect(touchEnded)
im sorry but i think you didnt understand what i need is that i want the player to only touch the certain part of the device if its not that part of device then dont execute code if its that part of device then execute code
You can use TouchMoved to do that, just check if the position is on the right side of the screen, e.g
local screenSizeX -- screen size on the X axis
local middle = screenSize/2 -- middle
-- when touch moved fires
local position = touch.Position -- the position
if (position.X >= middle) then
-- code
end
local UserInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local touchGui = script.Parent.TextButton
local screenSizeX =UDim2.new(1,0,0,0)
local middle = screenSizeX/2 -- middle
UserInputService.TouchMoved:Connect(function(touch, gameProccessedEvent)
local position = touch.Position -- the position
if (position.X >= middle) then
player:Move(Vector3.new(1,0,0))
end
end)
Sorry for leaving this out, you need to get the screen size from the Camera.ViewportSize
You’re not moving your character correctly, you’re attempting to move the Player object itself, which (as far as I know) doesn’t work. Trying using Humanoid:WalkToPoint on the Humanoid inside of the Player.Character.
local UserInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local touchGui = script.Parent.TextButton
local cam = workspace.CurrentCamera
local screenSizeX =cam.ViewportSize.X
local middle = screenSizeX/2 -- middle
UserInputService.TouchMoved:Connect(function(touch, gameProccessedEvent)
local position = touch.Position -- the position
if (position.X >= middle) then
player.Characte.Humanoid:Move(Vector3.new(1,0,0))
end
end)
actually i set it 1,0,0 because im making a 2d character movement controller and :Move is a real function why not check the devhub and the misspelled i fixed the spelling and it still doesnt work no errors
local UserInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local cam = workspace.CurrentCamera
local screenSizeX = cam.ViewportSize.X
local middle = screenSizeX/2 -- middle
UserInputService.TouchStarted:Connect(function(touch, gameProccessedEvent)
local position = touch.Position -- the position
if (position.X >= middle) then
player:Move(Vector3.new(1,0,0))
end
end)
UserInputService.TouchEnded:Connect(function()
player:Move(Vector3.new(0,0,0))
end)
local UserInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local cam = workspace.CurrentCamera
local screenSizeX = cam.ViewportSize.X
local middle = screenSizeX/2 -- middle
UserInputService.TouchStarted:Connect(function(touch, gameProccessedEvent)
local position = touch.Position -- the position
if (position.X >= middle) then
player:Move(Vector3.new(1,0,0))
end
end)
UserInputService.TouchStarted:Connect(function(touch, gameProccessedEvent)
local position = touch.Position -- the position
if (position.X <= middle) then
player:Move(Vector3.new(-1,0,0))
end
end)
UserInputService.TouchEnded:Connect(function()
player:Move(Vector3.new(0,0,0))
end)