Hello! I am a new scripter and am trying to make a gun script below.
My goal is that when the player clicks MouseButton1 it will fire their gun, while starting on the client script I got up to line 8 but couldn’t find a tutorial that talks about what to put in the parenthesis.
I found one that uses “fireEvent:FireServer(gun.Handle.Position, mouse.Hit.p)” but I don’t want to use mouse as it is outdated. Can anyone help me?
local gun = script.Parent
local UIS = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local fireEvent = ReplicatedStorage:WaitForChild("Fire")
local function onInputBegan(input, gameProcessed)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
fireEvent:FireServer()
end
end
Generally the wiki is really helpful, I’d recommend you use it to read more about the APIs and they have alot of useful tutorials on some frequently asked topics.
local gun = script.Parent
local UIS = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local fireEvent = ReplicatedStorage:WaitForChild("Fire")
mouseLocation = UIS:GetMouseLocation()
local function onInputBegan(input, gameProcessed)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
fireEvent:FireServer(gun.Handle.Position, mouseLocation)
end
end
Mouse.Hit.p does not return a CFrame, instead a vector3. Mouse.Hit returns a cframe. You still have to use Mouse over UserInputService because UIS does not support the equivalent of Mouse.Hit or Mouse.Target.