I would like to know how I could make a gun shoot where ever the screen is touched on a screen
1 Like
If you want to know the event to fire whenever this happens, it’s basically this one:
local tool = script.Parent
tool.Equipped:Connect(function(mouse)
mouse.Button1Up:Connect(function()
--do something
end)
end)
If you want to know how to make a gun, you can just search an online tutorial.
1 Like
Yes Ik that but how do I make it fire where I press?
what about Tool.Activated, you can try that
1 Like
The “.Activated” event of tool instances will fire on touch-screen devices when a the devices’ screen is touched.
This is by no means finished, it’s just a way to get you started.
--LOCAL
local userInput = game:GetService("UserInputService")
local tool = script.Parent
local remote = tool:WaitForChild("RemoteEvent")
local handle = tool:WaitForChild("Handle")
local camera = workspace.CurrentCamera
local equipped = false
local function onEquipped()
equipped = true
end
local function onUnequipped()
equipped = false
end
local function onScreenTouched(touchPosition, processed)
if processed then return end
if not equipped then return end
local unitRay = camera:ViewportPointToRay(touchPosition[1].X, touchPosition[1].Y)
remote:FireServer(unitRay)
end
tool.Equipped:Connect(onEquipped)
tool.Unequipped:Connect(onUnequipped)
userInput.TouchTap:Connect(onScreenTouched)
--SERVER
local tool = script.Parent
local handle = tool.Handle
local remote = tool.RemoteEvent
local debounce = false
local function onRemoteFired(player, unitRay)
if debounce then return end
debounce = true
local raycastResult = workspace:Raycast(handle.Position, unitRay.Direction * 250)
if raycastResult then
if raycastResult.Instance then
print(raycastResult.Instance.Name)
end
end
task.wait(0.5)
debounce = false
end
remote.OnServerEvent:Connect(onRemoteFired)
tool.rbxm (4.5 KB)
In addition to what I’ve already provided you’d need to handle projectile creation/results handling on the server.
2 Likes
Thank you so much it is really appreciated