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)
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)
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.
server script(script) in ServerScriptService
local script in StaterCharacterScripts - in StarterCharacter
Remote Event in ReplicatedStorage
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