I have been trying to repair the Crystal Sphere Drop gear, which dates back to 2013, for a game that I've been planning to make. While testing out the script, however, I get this error:
CFrame is not a valid member of Tool
How can I fix this?
Additionally, if I change any part of the code where it says Spear.CFrame to Spear.Handle.CFrame, the tool completely disappears from my backpack.
My code: (LocalScript, error originates from Line 92)
local Spear = script.Parent
local BallDropScript = script:WaitForChild('BallDropScript')
local creator = BallDropScript:WaitForChild('creator')
creator.Value = game.Players.LocalPlayer
local DesiredTarget = BallDropScript:WaitForChild('Target')
local Character = creator.Value.Character or creator.Value.CharacterAdded:wait()
local Fail = BallDropScript:WaitForChild('Fail')
delay(10, function()
Spear:Destroy()
end)
delay(0.5, function()
Spear.Handle.CanCollide = true
end)
local function FindCharacterAncestor(subject)
if subject and subject ~= workspace then
local humanoid = subject:FindFirstChild('Humanoid')
if humanoid then
return subject, humanoid
else
return FindCharacterAncestor(subject.Parent)
end
end
return nil
end
local function onTouched(part)
if not FindCharacterAncestor(part) then
-- see if we have an empty space to do the effect in
local at = (Spear.CFrame*CFrame.new(0,3.5,0)).p
BallDropScript:WaitForChild('Target').Value = at
local region = Region3.new(at + Vector3.new(-1,5,-1), at + Vector3.new(1,1,1))
local parts = workspace:FindPartsInRegion3(region)
for _, part in pairs(parts) do
if not FindCharacterAncestor(part) and part.CanCollide then
Fail.Value = true
Spear.Parent = nil
return
end
end
-- Create effect
BallDropScript.Parent = nil
BallDropScript.Disabled = false
BallDropScript.Parent = game.Workspace
Spear:Destroy()
return true
end
end
Spear.Handle.Touched:connect(onTouched)
local function Slerp(t, a, b)
local om = math.acos(math.min(1, a.unit:Dot(b.unit)))
if om < 0.01 then
return (1-t)*a + t *b
else
return (math.sin((1-t)*om)/math.sin(om))*a + (math.sin( t *om)/math.sin(om))*b
end
end
local function topVector(cf)
local _,_,_,_,r5,_,_,r8,_,_,r11,_ = cf:components()
return Vector3.new(r5,r8,r11)
end
function CFrameFromTopBack(at, top, back)
local right = top:Cross(back)
return CFrame.new(at.x, at.y, at.z,
right.x, top.x, back.x,
right.y, top.y, back.y,
right.z, top.z, back.z)
end
local frac = 0
local start = Spear.Handle.Position
local target = DesiredTarget.Value
local initialDir = (CFrame.new(start, target)*CFrame.Angles(0.5, 0, 0)).lookVector
local finalDir = (CFrame.new(start, target)*CFrame.Angles(-0.5, 0, 0)).lookVector
local distance = (start-target).magnitude
local mid = (start + initialDir*distance/2)
local startT = tick()
local velo = 80
local duration = distance / velo
--
local ignore = {Spear}
while true do
wait()
local elapsed = tick()-startT
local frac = elapsed / duration
if frac > 1 then
break
end
local lastAt = (Spear.CFrame*CFrame.new(0,3.5,0)).p
local at = start:Lerp(mid,frac):Lerp(mid:Lerp(target,frac),frac)
local dir = Slerp(frac,initialDir,finalDir)
Spear.CFrame = CFrame.new(at, at+dir)*CFrame.Angles(-math.pi/2,0,0)
local newAt = (Spear.CFrame*CFrame.new(0,3.5,0)).p
local ray = Ray.new(lastAt, (newAt-lastAt))
local hit, loc = workspace:FindPartOnRayWithIgnoreList(ray, ignore)
while hit do
if onTouched(hit) then
return
end
table.insert(ignore, hit)
hit, loc = workspace:FindPartOnRayWithIgnoreList(ray, ignore)
end
end
Spear:Destroy()

7 comments
I already did try that, but whenever I do, the tool disappears from my Backpack. Is there any likely way I could tweak the code to NOT make it disappear?
are you making sure the CFrame is the correct one? if you have to play around with it, you definitely should, i can barely read that so theres not much i can say
the handle of the tool?
Yes, he means the handle.
Not sure about these lines, Line 1 = local Spear = script.Parent Line11 - 13: delay(10, function() Spear:Destroy() end)
Kinda looks like it removes it self after 10 secs?
How do you guys know this stuff, I can't even remember the script for a kill part.