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

My Knife doesn't spin sometimes and just moves. How do I fix this?

Hello, I'm having a problem with something, It's about CFrame Angles, the problem is that the knife sometimes doesn't spin when thrown, lemme show a gif to show the problem

GIF Here

As you can see, it sometimes doesn't even spin

Here's the script, the touched makes use of items such as canCollide part detection

-- In the script inside the thrown knife
local clone = script.Parent
local touched = false
local RunService = game:GetService("RunService")

local function GetTouchingParts(part)
   local connection = part.Touched:Connect(function() end)
   local results = part:GetTouchingParts()
   connection:Disconnect()
   return results
end

Step = RunService.Stepped:Connect(function()
        if clone.Parent ~= workspace then return end
	--clone.CFrame = clone.CFrame * CFrame.fromEulerAnglesXYZ(math.rad(-15),0,0)
	clone.CFrame = clone.CFrame * CFrame.Angles(math.rad(-15),0,0)
	local results = GetTouchingParts(clone)
	for i,v in pairs(results) do
		if not v.Parent:FindFirstChild("Humanoid") or (v:IsA("BasePart") and v.Transparency ~= 1) then
			if #results > 0 then
				Step:Disconnect()
			end
		else
			table.remove(results,i)
		end
	end
end)

Any help is appreciated

2 answers

Because you and your target's distance is close,it starts spinning but because it hits the target fast,you can't see it while spinning.You can change the rotation values and this might fix it.

As stated previously, the reason being that it only works sometimes is because the distance between you and the part is -15 studs so it will only work when you're/part is -15 studs away.

You could try changing the rotational values here. It's also recommended to use bodygyros when making things act like changing a physical state for example.

-- In the script inside the thrown knife
local clone = script.Parent
local touched = false
local RunService = game:GetService("RunService")

local function GetTouchingParts(part)
   local connection = part.Touched:Connect(function() end)
   local results = part:GetTouchingParts()
   connection:Disconnect()
   return results
end

Step = RunService.Stepped:Connect(function()
        if clone.Parent ~= workspace then return end
          local X, Y, Z = .1, 0, 0
            while wait() do
              Part.CFrame = Part.CFrame*CFrame.Angles(X, Y, Z)
    clone.CFrame = clone.CFrame * CFrame.Angles(math.rad(-15),0,0)
    local results = GetTouchingParts(clone)
    for i,v in pairs(results) do
        if not v.Parent:FindFirstChild("Humanoid") or (v:IsA("BasePart") and v.Transparency ~= 1) then
            if #results > 0 then
                Step:Disconnect()
            end
        else
            table.remove(results,i)
            end
        end
    end
end)

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