Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

why isnt my projectile system damaging ontouch?

Asked by 2 years ago

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?????

2 answers

Log in to vote
1
Answered by 2 years ago

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)
0
im still a starter so i don't know how to set up remote events. explanation please? pakancina 19 — 2y
0
there wasn't any remote events in her answer. basically, remote events can transfer data from client to server, and vice versa. T3_MasterGamer 2189 — 2y
0
i meant his T3_MasterGamer 2189 — 2y
0
He said in the script --youll need to set up some remote events to deal real damage--- pakancina 19 — 2y
View all comments (2 more)
0
actually i set this script up and it kinda woks. it kills the npc instantly. is thee a way to deal like 10 damage or something? pakancina 19 — 2y
0
okay this is interesting. i set up the remote event, and now the projectiles damage me when they touch the npc?????? pakancina 19 — 2y
Ad
Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

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)
0
when i copy it there ae some red lines on the line 20 is anot a typo? pakancina 19 — 2y
0
line 12* pakancina 19 — 2y
0
and also if you can, make the damage a value, so it can be changed by lets say touching a part pakancina 19 — 2y
0
Oh right sorry abt that, I fixed line 12 T3_MasterGamer 2189 — 2y
View all comments (5 more)
0
Oh, about @SimpleFlame saying about using remote events to damage players, it's because if player died in client script it wont always send to the server. So yes, you do need to make remote events. Make one in ReplicatedStorage named "DealDamage" and copy my script. T3_MasterGamer 2189 — 2y
0
thanks! ill try it as soon as i get a chance, ill let you know if ot works pakancina 19 — 2y
0
ummmm now the projectiles have gravity fsr, dont deal damage like before and dont dissapear. hmmm pakancina 19 — 2y
0
did you pasted the whole script? pls look down at the script. you can see "in server script" line, remove that line from the client and put that line in a script in serverscriptstorage T3_MasterGamer 2189 — 2y
0
i did. the script from before actually dealt damage, now i just need the projectiles to dissapear pakancina 19 — 2y

Answer this question