Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why is my shuriken killing me instead of throwing it?

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

1 comment

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

1 answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.