Gun is not automatic

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)

I assume Deactivated is a boolvalue, so you should do this:

until script.Parent.Deactivated.Value

Deactivated isn’t a bool value, it’s something that can be called when a script is placed inside of a Tool class.

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

You can do this;

script.Parent.Activated:Connect(function()

local shouldContinue = true
script.Parent.Deactivated:Once(function()
       shouldContinue = false
end)


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 shouldContinue == false
end)
2 Likes

all you need to do is change the line to

until script.Parent.Parent == player.Backpack

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!

That would theoretically make it so that it would stop firing when my player model is inserted into my own backpack.

no. script.Parent is the tool, and script.Parent.Parent is EITHER the character or the backpack. if it’s the backpack, it’s not equipped

1 Like

I see where you’re going, but I need it to stop firing when the player releases MouseButton1 instead of when it is unequipped.

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

1 Like

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 (:skull:) - The firing is more consistent when I change the delay from 0.2 to 0.1!??!?! Guess it works.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.