Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

i made a gun but the damge age script for 3 sec then it stopes how do i fix?

here is error attempt to index field 'Parent' (a nil value)

-- the script
script.Parent.Touched:Connect(function(hit)
	
	script.Parent.CanCollide = true
	if hit.Parent:FindFirstChild("Humanoid")
		
		then hit.Parent.Humanoid.Health  = hit.Parent.Humanoid.Health - 2
	script.Parent:remove()
	
	end
end)

the script i am using for it

local play = game.Players.LocalPlayer
local char = play.Character
local mouse = play:GetMouse()
local fire = true


script.Parent.Parent.Activated:Connect(function()
	while fire == true do
		wait()
		
		
	local clone = game.Workspace.lazer:Clone()
	local b = game.Workspace.dmg.Gun:Clone()
local r = game.Workspace.dmg.flame:Clone()
	r.Disabled = false
	b.Disabled = false
	local x =  Instance.new("BodyVelocity",clone)
	x.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
	x.Velocity = mouse.Hit.lookVector* 90
	clone.Parent = game.Workspace
	clone.Position = script.Parent.Position *Vector3.new(1,0,0)
	r.Parent = clone
	b.Parent = clone
	end
end)
script.Parent.Parent.Deactivated:Connect(function()
	fire = false
	wait(1)
	fire = true
end)

2 comments

0

:remove is deprecated. Use :Destroy()

0

Also is the top code in a script and the bottom a local script?

1 answer

✓ Accepted answer

The :Remove() feature is deprecated, use :Destroy() instead.

Make sure to have the bottom script in a LOCALSCRIPT to ensure that it can run properly. If you have any more questions please feel free to ask here again on Scripting Helpers.

1 comment

0

Don't copy someone's comments, it won't help the asker

This discussion is preserved as it was. New answers, comments, and votes are closed.