Projectile not dealing any damage

I made a projectile but it’s not dealing any damaging. Any help is appreciated.
robloxapp-20230626-1558101.wmv (864.8 KB)

This script is in the projectile:

local timeBetweenDamage = 1
local damagePerTick = 200

local charsBeingDamaged = {}

script.Parent.Touched:connect(function(part)
	if part.Parent:findFirstChild("Humanoid") then
		local char = part.Parent
		if not table.find(charsBeingDamaged,char) then
			table.insert(charsBeingDamaged,char)
			local hum = part.Parent.Humanoid
			local stillTouching = true
			while stillTouching do
				hum:TakeDamage(damagePerTick)
				wait(timeBetweenDamage)
				local touchingParts = script.Parent:GetTouchingParts()
				stillTouching = false
				for i,v in next,char:GetChildren() do
					if table.find(touchingParts,v) then
						stillTouching = true
					end
				end
			end
			for i,v in next,charsBeingDamaged do
				if v == char then
					table.remove(charsBeingDamaged,i)
				end
			end
		end
	end
end)

just to make sure, this is in a server script and the projectile is duplicated on the server yeah?

The script works perfectly fine, excepted you could damage yourself(unless you want that).

yep, here’s the duplication script that’s in StarterCharacterScripts:

local Player = game.Players.LocalPlayer
local uis = game:GetService("UserInputService")
uis.InputBegan:connect(function(input,processed)
	if input.UserInputType == Enum.UserInputType.Keyboard and input.KeyCode == Enum.KeyCode.Z  and not processed then
		local Part = game.ReplicatedStorage.BasicProjectile:Clone()
		Part.Parent = game.Workspace
		Part.CFrame = Player.Character.HumanoidRootPart.CFrame * CFrame.new(-.1,3,-5)
		local y = Instance.new("BodyVelocity")
		y.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
		y.Velocity = Player.Character.HumanoidRootPart.CFrame.lookVector*150
		y.Parent = Part
		Part.Orientation = script.Parent.HumanoidRootPart.Orientation
		script.Disabled = true
		wait(0.2)
		script.Disabled = false
	end
end)

You should use raycast!.
I offer you to learn how to use raycast,
Its very helpful.
Good luck understanding raycast :sob::sob:
some pain…

this is all done on client, in order for the server script to work in the part(projectile) it has to be cloned on the server. all you need to do is launch an remote Event with some values.

What would the code look like? (Sorry I only know how to edit/modify code)

server script(script) in ServerScriptService
local script in StaterCharacterScripts - in StarterCharacter
Remote Event in ReplicatedStorage

Script_ (Trainmaster2341 Editing) - Roblox Studio 4_19_2023 8_39_44 PM (3)

Server Script Code:

local remote = game.ReplicatedStorage:WaitForChild("RemoteEvent")
local BasicProjectile = game.ReplicatedStorage:WaitForChild("BasicProjectile")

remote.OnServerEvent:Connect(function(plr)
	
	local Part = BasicProjectile:Clone()
	Part.Parent = game.Workspace
	Part.CFrame = plr.Character.HumanoidRootPart.CFrame * CFrame.new(-.1,3,-5)
	local y = Instance.new("LinearVelocity")
	y.MaxForce = math.huge
	y.VectorVelocity= plr.Character.HumanoidRootPart.CFrame.lookVector*150
	y.Attachment0 = BasicProjectile.Attachment
	y.Parent = Part
	Part.Orientation = plr.Character.HumanoidRootPart.Orientation
	game.Debris:AddItem(y,2)
       game.Debris:AddItem(Part,4)
end)

Client Script Code:

local uis = game:GetService("UserInputService")
local remote = game.ReplicatedStorage:WaitForChild("RemoteEvent")
local Player = game.Players.LocalPlayer

uis.InputBegan:connect(function(input,processed)
	if input.UserInputType == Enum.UserInputType.Keyboard and input.KeyCode == Enum.KeyCode.Z  and not processed then
		remote:FireServer()
	end
end)

I replaced Body Velocity with linear Velocity as Body velocity is no longer supported, but if you do use linear velocity make sure to add an attachment in your projectile.

Changes to the code may be necessary. Hope this helps : D

i dont think scripts can run from within server storage they needa be in serverscriptservicve

1 Like

The Remote is fired but the server script doesn’t do anything. I tested it by putting “print(“Works?”)” in the server script.

exactly, but did you try putting the serverscript in serverscriptservice?

thanks for noticing my mistake. I can’t believe I did that. If I have any other mistakes please correct me.

1 Like

Thanks for the help! I will try to learn more code. :+1:

1 Like

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