I was wondering how I would script a tool to spray water (obviously using particle emitters) in the spot where somebody clicks (I understand that to do this I would need raycasting, I just don’t understand how to do the math so that the sprayer points where it wants to shoot and the water lands where I want it to).
Heres a gun system i made that maybe can make your gun work
For that you will probably have to use a remote event
And split the gun working into a local and a server script
And this will only work if its a tool
-- Local Script
-- // Variables
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local tool = -- where the tool is
local remote = -- a remote event
-- // Firing
tool.Activated:Connect(function()
local hitpos = mouse.Hit.p
remote:FireServer(hitpos)
end
-- Server Script
local remote = -- the remote event
local firepart = -- the part of the gun that fires you probably know it
remote.OnServerEvent:Connect(function(player, hit)
local raycast = workspace:Raycast(firepart.Position, (hit.Position-firepart.Position).unit*1000 -- the maximum distance that the raycast will reach)
-- the rest of the things you want to add
end
Hope this helped!
I might try modifying this to work to my needs.
Edit: Unfortunately, it didn’t work.
1 Like