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

Why is my shuriken killing me instead of throwing it?

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

I made a shuriken, and when I throw it, it kills me instead. Help! There's no errors either. Just an infinite yield on ":WaitForChild()"

local Tool = script.Parent.Parent
local Player = game:GetService("Players").LocalPlayer
--local Animations = Tool.Animations
--local ThrowAnimation = Animations.ThrowAnimation
local Debounce = false
local ThrowSound = Tool.Handle.Throw
local Mouse = Player:GetMouse()
local PlayAnimation = game:GetService("ReplicatedStorage"):WaitForChild("PlayAnimation")
local StopAnimation = game:GetService("ReplicatedStorage"):WaitForChild("StopAnimation")
Tool.Activated:Connect(function()
    if Debounce == false then
        Debounce = true
        ThrowSound:Play()
        Throw()
        wait(0.201)
        Debounce = false
    end
end)

function Throw()
    local NewProjectile = Tool.Handle:Clone()
    NewProjectile.Parent = workspace
    local BodyVelocity = Instance.new("BodyVelocity")
    BodyVelocity.Parent = NewProjectile
    BodyVelocity.Velocity = Player.Character.Head.CFrame.lookVector*90
    NewProjectile.Touched:Connect(function(hit)
        if hit and hit.Parent:WaitForChild("Humanoid") then
            hit.Parent.Humanoid:TakeDamage(25)
            NewProjectile:Destroy()
        end
    end)
end
0
You're supposed to use a FindFirstChild, not WaitForChild. You are waiting for a humanoid which does not exist, and therefore yields the script. Also, you should connect Throw to the Touched event User#19524 175 — 5y

1 answer

Log in to vote
0
Answered by
Hizar7 102
5 years ago

I'm not too faimilar with clone but i believe you had that wrong, I am using a new part as a substitute. Also you needed to add a maxForce and a new cframe for the part, let me know if this works for you! :)

local Tool = script.Parent
    local Player = game:GetService("Players").LocalPlayer
    local Animations = Tool.Animations
    local ThrowAnimation = Animations.ThrowAnimation
    local Debounce = false
    local ThrowSound = Tool.Handle.Throw
    local Mouse = Player:GetMouse()
    local PlayAnimation = game:GetService("ReplicatedStorage"):WaitForChild("PlayAnimation")
    local StopAnimation = game:GetService("ReplicatedStorage"):WaitForChild("StopAnimation")
    Tool.Activated:Connect(function()
        if Debounce == false then
        Debounce = true
           -- ThrowSound:Play()
            Throw()
            wait(0.201)
            Debounce = false
        end
    end)

    function Throw()
        local NewProjectile = Instance.new('Part')--Tool.Handle:Clone()
    game.Debris:AddItem(NewProjectile)
        local BodyVelocity = Instance.new("BodyVelocity",NewProjectile)
        BodyVelocity.Parent = NewProjectile
        BodyVelocity.Velocity = Player.Character.Head.CFrame.lookVector*90
    BodyVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
    NewProjectile.Parent = game.Workspace -- added at a lower line
    NewProjectile.CFrame = Player.Character.UpperTorso.CFrame *CFrame.new(0, 0, -9)
    wait(0.5) -- dont like the spam of the parts 
        NewProjectile.Touched:Connect(function(hit)
            if hit and hit.Parent:WaitForChild("Humanoid") then
                hit.Parent.Humanoid:TakeDamage(25)
                NewProjectile:Destroy()
            end
        end)
    end
Ad

Answer this question