There seems to be a mistake in the code you provided. When the player taps on the right side of the screen, the code says to call the Move function with the argument “Left” instead of “Right”. Here is how the corrected code should look:
Uis.TouchStarted:Connect(function(Input, gameProccedEvent)
if not gameProccedEvent then
if Input.Position.X <= Mouse.X / 2 then
Move("Left")
else
Move("Right")
end
end
end)
I hope this helps! Let me know if you have any other questions.
That part of the code was correct, when I used a mouse click event to fire the move function everything was working until I used the “TouchedStarted” event
I apologize for misunderstanding your question. If the issue you are experiencing is that the player is moving in the opposite direction of what you expect when you tap the right side of the screen, it is because the Input.Position.X value is compared to half the value of Mouse.X .
If the Input.Position.X value is on the right side of the screen, it will be greater than half the value of Mouse.X , and the player will move left. To fix this, you can change the code to the following.
Uis.TouchStarted:Connect(function(Input, gameProccedEvent)
if not gameProccedEvent then
if Input.Position.X < Mouse.X / 2 then
Move("Left")
else
Move("Right")
end
end
end)
This will make the player move right when you tap the right side of the screen. I hope this helps. Let me know if you have any other questions.
I almost feel like I’m confusing you, the uis.TouchedStarted is just not working, I did a little test to change the text on a text label when the player tapped the screen by using uis.TouchedStarted and I did not change the text. I’m just wondering if there is an alternat option then using uis.TouchedStarted.
1.My phone dose have touch screen
2.None of the other touched events are working
3.The code is not yielding it worked fine when I switched it to a mouse event
And turn of events the touched event is working now, although it’s not getting the Left or Right correct
On the third line, you’re compating the touch position with Mouse.X. I don’t think this is what you mean to do, since you’re basically comparing the touch position with it’s own position. I’m actually not even sure if Mouse.X works on mobile.
I think you mean something like this:
if Input.Position.X <= (workspace.Camera.ViewportSize.X / 2) then
workspace.Camera.ViewportSize.X returns the current size of the camera in the x direction.
The mouse.x represented the size of the screen the nouse had no part in it not working, i did change it but still had the same problem, it seems when i clikc on the right left side it just makes me go right instead of left
Add a print statement that prints “Left”/“Right” each time before you call your Move() function and check whether the if statement works normally and prints what it should. If it does, then the problem seems to be something to do with your function and not this piece of code.