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

Why is it that my Rocket Launcher's Explosion Hit Detection is not firing?

Asked by
Mr_Unlucky 1085 Moderation Voter
5 years ago
Edited 5 years ago

I'm trying to make a Rocket Launcher, and basically I want it so that when someone is hit by an explosion (detected via the Hit event), it will damage their humanoid by 30 and then proceed to insert a "CreatorValue" to log that a person killed them (in a future script).

The entire script is listed below, but the most important snippet of code to check over would be the touched event that fires.

The following scripts are contained in a Server-Side script that is cloned into a Rocket that is spawned in another script that is connected to a remote event responsible for spawning the rocket.

The "onTouched()" function fires when the rocket is touched. Whne onTouched is called, it runs a conditional statement that checks if the HumanoidRootPart is near the Rocket, so it can insert a forcefield to allow the player to rocket jump. Afterwards, it spawns in an explosion and tweaks its properties. It then creates an event that fires when something touches and explosion, which is then calls the function "onHit". onHit() basically gets the character and it goes through a conditional statement checking if the character it hit is actually a character and not something part of the map. If it returns as true, it gets the Humanoid and inserts a CreatorValue and makes the humanoid take damage.

The problem is that the function is not being called, and whenever i check the output to see if the dummy text has been printed, nothing appears.

CODE SNIPPET

01function onTouched()
02    if (HumanoidRootPart.Position - Rocket.Position).Magnitude <= 10 then
03        local ForceField = Instance.new("ForceField")
04        ForceField.Visible = false
05        ForceField.Parent = Character
06        game:GetService("Debris"):AddItem(ForceField,.5)
07    end
08 
09    local function onHit(Part)
10        local TargetCharacter = Part:FindFirstAncestorWhichIsA("Model")
11 
12        print("Test1")
13 
14        if game:GetService("Players"):GetPlayerFromCharacter(TargetCharacter) then
15            local TargetHumanoid = TargetCharacter:FindFirstChild("Humanoid")
View all 39 lines...

FULL SCRIPT

01local Rocket = script.Parent
02local CreatorValue = Rocket:WaitForChild("CreatorValue")
03 
04local Player = CreatorValue.Value
05local Character = Player.Character or Player.CharacterAdded:Wait()
06local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
07 
08local TouchedEvent
09 
10local DebrisService = game:GetService("Debris")
11 
12function onTouched()
13    if (HumanoidRootPart.Position - Rocket.Position).Magnitude <= 10 then
14        local ForceField = Instance.new("ForceField")
15        ForceField.Visible = false
View all 52 lines...

Answer this question