ok. i made a script that lets you shoot projectiles when you press the key "e" now i need the projectiles to damage npcs on touch. i tried putting every damage script out there in the projectile, nothing worked. heres the script:
local sound = script.fire local tweenservice = game:GetService("TweenService") local plr = game.Players.LocalPlayer local tear1 = game.ReplicatedStorage.Player1tear local UIS = game:GetService("UserInputService") UIS.InputBegan:connect(function(input) if input.KeyCode == Enum.KeyCode.E then print("Working") sound:Play() local clonetear = tear1:Clone() clonetear.Parent = game.Workspace clonetear.CFrame = plr.Character.HumanoidRootPart.CFrame + plr.Character.HumanoidRootPart.CFrame.lookVector * 5 tweenservice:Create(clonetear,TweenInfo.new(1,0,0),{CFrame = plr.Character.HumanoidRootPart.CFrame + plr.Character.HumanoidRootPart.CFrame.lookVector * 40,Transparency = 1},Enum.EasingStyle.Quint,Enum.EasingDirection.Out):Play() game.Debris:AddItem(2.5,clonetear) -- change the number of time to wait until the ball dissapear,this can be the ball range untill get deleted end end)
keep in mind: theres a projectile in replicated storage called tear1 theres a sound in the script called fire the localscript in the codeblock goes into starterplayerscripts. any help?????
Seems like you're missing a .Touched which will trigger when the projectile hits something.
UIS.InputBegan:connect(function(input) if input.KeyCode == Enum.KeyCode.E then print("Working") sound:Play() local clonetear = tear1:Clone() -- Touched event clonetear.Touched:Connect(function(hit) local hitHumanoid = hit.Parent:FindFirstChildOfClass("Humanoid") -- Check for a humanoid if hitHumanoid then -- You'll need to set up some remote events to deal real damage. hitHumanoid:TakeDamage(10) -- Deal damage game.Debris:AddItem(0, clonetear) -- Remove projectile end end) clonetear.Parent = game.Workspace clonetear.CFrame = plr.Character.HumanoidRootPart.CFrame + plr.Character.HumanoidRootPart.CFrame.lookVector * 5 tweenservice:Create(clonetear,TweenInfo.new(1,0,0),{CFrame = plr.Character.HumanoidRootPart.CFrame + plr.Character.HumanoidRootPart.CFrame.lookVector * 40,Transparency = 1},Enum.EasingStyle.Quint,Enum.EasingDirection.Out):Play() game.Debris:AddItem(2.5,clonetear) end end)
You will need to use the BasePart.Touched
event in the projectile. If you don't know what the Touched even is, it fires when a part touches it.
This script below is the same as @SimpleFlame's answer but I modified a bit.
-- in client script UIS.InputBegan:Connect(function(input, isChatting) if not isChatting then -- checks if the player is not typing in chat if input.KeyCode == Enum.KeyCode.E then print("Working") sound:Play() local clonetear = tear1:Clone() clonetear.Touched:Connect(function(hit) local hitHumanoid = hit.Parent:FindFirstChildOfClass("Humanoid") local hitPlayer = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent) -- checks if it's a player if hitHumanoid and not hitPlayer then -- checks if it's not a real player game:GetService("ReplicatedStorage"):WaitForChild("DealDamage"):FireServer(10) -- Deal damage game.Debris:AddItem(0, clonetear) -- Remove projectile end end) clonetear.Parent = game.Workspace clonetear.CFrame = plr.Character.HumanoidRootPart.CFrame + plr.Character.HumanoidRootPart.CFrame.lookVector * 5 clonetear.Velocity = clonetear.CFrame.lookVector * 40 -- shoots the projectile tweenservice:Create(clonetear,TweenInfo.new(1,Enum.EasingStyle.Quint,Enum.EasingDirection.Out),{Transparency = 1}):Play() game.Debris:AddItem(2.5,clonetear) end end end) -- in server script (ServerScriptService) game:GetService("ReplicatedStorage"):WaitForChild("DealDamage").OnServerEvent:Connect(function(player, damage) local character = player.Character or player.CharacterAdded:Wait() local humanoid = character:WaitForChild("Humanoid") humanoid:TakeDamage(damage) end)