Code is in a localscript inside of a tool. This isn’t the full script, just a function inside of it.
script.Parent.Activated:Connect(function()
repeat task.wait(0.2)
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local mousepos = mouse.Hit.Position
local target = mouse.Target
script.Parent.shot:FireServer(mousepos)
reloadable = true
until script.Parent.Deactivated
end)
oh, so it’s an event signal. but it’s not a boolean so it’s not gonna be false. you can check if it’s parented to the character to see if it’s equipped.
also, a remote event needs to be in ReplicatedStorage so the server can access it, not just on the client
It doesn’t look like there’s anything wrong with your script in terms of delaying, but the firing is inconsistent. It fires pretty rapidly and then slows down for 2 or 3 rounds, and then gets faster. I appreciate the help though!
oh, I thought Deactivated meant when it was unequipped. I don’t know why the script the other person posted above doesn’t work. maybe it’s slow because of the remote event
The little blurb in Studio says that Deactivated is called when the player releases their click when the item is equipped. It may be the remote event, but that is the only way (I think) to communicate between Local and Server scripts. In my tool, the server script creates the raycast that does the damage, and the local script does the activation stuff.
Edit - I might be able to put the Activated function into the server script so there isn’t a need for a remote event, and the rest of the local script will do the animating.
Edit 2 - Never mind, the remote event needs to be called with mousepos so that the raycast in the server script will go to the mouse position.
Edit 3 () - The firing is more consistent when I change the delay from 0.2 to 0.1!??!?! Guess it works.