Hello, I am making a randomizer game similiar to item asylum and i was wondering if anyone could make it so if you’re on mobile, instead of shooting normally, aka where you click is, bla bla bla, i was wondering if anyone could help me with making it shoot where the crosshair is, if you’re on mobile. The crosshair is a imagelabel inside of a frame in a screengui. I made it so it pops up if you equip the weapon, but i do not know how to make it so it actually shoots there. Please do not optimize or change unnecessary parts of the script, as it works perfectly and simply, and i like it like that, just change it so you can make it shoot where the crosshair is if you’re on mobile.
Local script:
local Tool = script.Parent
local RE = Tool.RemoteEvent
local Anim = Tool.Animation
local Plr = game.Players.LocalPlayer
local Char = Plr.Character
local Hum = Char.Humanoid
local AnimTrack = Hum:LoadAnimation(Anim)
local debounce = false
local ShootAnim = Tool.Shoot
local Mouse = Plr:GetMouse()
local isMobile = game:GetService("UserInputService").TouchEnabled
local isDesktop = game:GetService("UserInputService").KeyboardEnabled
Tool.Equipped:Connect(function()
AnimTrack:Play()
AnimTrack.Looped = true
if isMobile then
Plr.PlayerGui["Mobile crosshair"].Enabled = true
end
end)
Tool.Unequipped:Connect(function()
AnimTrack:Stop()
Plr.PlayerGui["Mobile crosshair"].Enabled = false
end)
Tool.Activated:Connect(function()
if debounce == false then
debounce = true
local Shoot = Hum:LoadAnimation(ShootAnim)
Shoot:Play()
RE:FireServer(Mouse.Hit.Position)
task.wait(1.5)
debounce = false
end
end)
Server script
local tool = script.Parent
script.Parent.RemoteEvent.OnServerEvent:Connect(function(Plr, MousePos)
tool.Handle["Pistol Shoot"].Playing = true
local RayParams = RaycastParams.new()
RayParams.FilterDescendantsInstances = {Plr.Character}
RayParams.FilterType = Enum.RaycastFilterType.Exclude
if tool.Handle then
local RayCastResult = workspace:Raycast(tool.Handle.Position, (MousePos - tool.Handle.Position) * 300, RayParams)
if RayCastResult then
local RayInstance = RayCastResult.Instance
local Model = RayInstance:FindFirstAncestorOfClass("Model")
if Model then
if Model:FindFirstChild("Humanoid") then
if RayInstance.Name == "Head" then
Model:FindFirstChild("Humanoid"):TakeDamage(40 * Plr.AttackMultiplier.Value)
tool.Handle.Headshot.Playing = true
else
Model:FindFirstChild("Humanoid"):TakeDamage(10 * Plr.AttackMultiplier.Value)
end
end
end
end
end
end)