MobileButton Gui HumanoidRootPart Look CFrame Issue Interference

The title may be a little confusing, but recently I have been trying to configure mobile compatibility with all my gears/tools in my game and I’ve come across some issues with the skills.

Currently, the script works off of an InputBegan and InputEnded method for PC users.

though I just recently added this for mobile -

IceButton.Button.TouchTap:Connect(function(TouchPositions, TouchState)
	if Holding.Value == "R" then
		isHolding = false
		SkillsHandler:FireServer("R", Mouse:GetHit().Position)
		Animations.R:AdjustSpeed(1)
	else
		SkillsHandler:FireServer("Hold", "R")
	end
end)

Currently I have a script like this -

That basically makes the HumanoidRootPart adjust its CFrame towards the look of the mouse. Of course, for mobile, it’s just whatever they tap on the screen.

My issue is that, when the user tries to shoot that direction and press the button at the same time, it directs the humanoidrootpart instantly toward that Image button.

I’ve tried TouchLongPress but I still can’t solve this issue with that. Any idea what I could possibly do? Maybe rework the code or methods I am using?

RPReplay_Final1676872320_AdobeExpress

Here’s an example of the issue any ideas? ^

Yeah its probably raycasting at the button instead of the center.

Try combining these 2 to get the hit position at the center of the screen

1 Like

Little confused with Vector2 though, because I want to make the humanoid root-part look directly at the CFrame of the center in the case you’re telling me.

Which CFrame seems to be Vector3?

How could I go about changing this →

HumRP.CFrame = CFrame.lookAt(HumRP.Position, Mouse:GetHit().Position)

Edit - How would I get the Vector3 position from the middle of the screen? just found this resource, will check this out first.

Edit -

repeat
					local unitRay = currentCamera:ScreenPointToRay(Viewport_Size.X / 2, Viewport_Size.Y / 2 + game:GetService("GuiService"):GetGuiInset().Y)
					local raycastResult = workspace:Raycast(unitRay.Origin, unitRay.Direction * CAST_LENGTH, raycastParams)
					if raycastResult and raycastResult.Position then
						HumRP.CFrame = CFrame.lookAt(HumRP.Position, raycastResult.Position)
					end
					task.wait()
				until Holding.Value ~= "R"

This seems to be facing the character towards the center of the screen, but the opposite way. It’s still shooting towards the ground as well.

Replying to myself →

Solved this by adding a wait delay, before firing to the server. So it gets the correct holding position.

IceButton.Button.TouchTap:Connect(function(TouchPositions, TouchState)
	if Holding.Value == "R" then
		isHolding = false
		wait(1) -- ADDED A WAIT DELAY
		SkillsHandler:FireServer("R", Mouse:GetHit().Position)
		Animations.R:AdjustSpeed(1)
	else
		SkillsHandler:FireServer("Hold", "R")
	end
end)

Still will need to figure out how to correctly use the center of the screen later in the future. Works fine now though :slight_smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.