Hello! So ive been making a game but whenever i playtested it would always lag because of this error
CFrame is not a valid member of Script "Workspace.Dolls.Script"
Dolls is a folder for where i keep my parts, but the script keeps saying that script.Parent is the script itself, I checked multiple times.
Heres the script:
local part = script.Parent
local collected = false
local Players = game:GetService("Players")
game:GetService("RunService").Heartbeat:Connect(function(dt)
if part and part.Parent then
part.CFrame = part.CFrame * CFrame.Angles(0, math.rad(180 * dt), 0)
end
end)
part.Touched:Connect(function(hit)
if collected then return end
local character = hit.Parent
local humanoid = character:FindFirstChildWhichIsA("Humanoid")
local player = Players:GetPlayerFromCharacter(character)
collected = true
for _, plr in ipairs(Players:GetPlayers()) do
local leaderstats = plr:FindFirstChild("leaderstats")
if leaderstats then
local wegasValue = leaderstats:FindFirstChild("Wegas") or leaderstats:FindFirstChild("wegas")
if wegasValue and (wegasValue:IsA("IntValue") or wegasValue:IsA("NumberValue")) then
wegasValue.Value += 1
end
end
end
local sound = part:FindFirstChild("Collect")
if sound and sound:IsA("Sound") then
sound:Play()
end
part.Anchored = true
part.CanCollide = false
part.Transparency = 1
game:GetService("SoundService").SpawnedWega:Play()
character.HumanoidRootPart.Anchored = true
local wega = game:GetService("ServerStorage").Characters.Wega:Clone()
wega.Parent = workspace.Chars
task.wait(1.5)
game:GetService("SoundService").SpawnedWega:Destroy()
game:GetService("SoundService").Theme:Play()
game:GetService("ServerStorage").Map:Clone().Parent = workspace
local wegastart = game:GetService("ServerStorage").WegaScript
wegastart.Parent = wega
game:GetService("ServerStorage").Dolls:Clone().Parent = workspace
wega.Normal:Play()
task.wait(0.5)
character.HumanoidRootPart.Anchored = false
for i = 1, 12 do
if part and part.Parent then
part.CFrame = part.CFrame * CFrame.new(0, 0.7, 0)
end
task.wait(0.03)
end
if part and part.Parent then
part:Destroy()
end
end)
This is the hierarchy:
