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

Why isn't this spawning?

Asked by 8 years ago

I'm trying to make a shield, and when you press t a part is supposed to spawn 1 stud in front of you, but instead it doesn't spawn at all and returns this error: bad argument #3 to CFrame (CFrame expected, got Vector3)

local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local chr = plr.Character or plr.CharacterAdded:wait()

local shield = Instance.new("Part")
shield.Anchored = true
shield.Transparency = .8
shield.CanCollide = false
shield.FormFactor = "Custom"
shield.Size = Vector3.new(.2,.2,.2)
shield.BottomSurface = "Smooth"
shield.TopSurface = "Smooth"

mouse.KeyDown:connect(function(key)
    if key == 't' then
        chr.Humanoid.WalkSpeed = 0
        clone = shield:Clone()
        clone.Parent = workspace
        clone.CFrame = chr.Torso.CFrame.lookVector*10

        clone.Touched:connect(function(p)
            if p and p.Locked == false then
                p:Destroy()
            end
        end)
        for i = 1,25 do
            game:GetService('RunService').RenderStepped:wait()
            clone.Size = clone.Size + Vector3.new(.2,.2,0)
        end
    end
end)

mouse.KeyUp:connect(function(key)
    if key == 't' then
        chr.Humanoid.WalkSpeed = 16
        for i = 1,25 do
            game:GetService('RunService').RenderStepped:wait()
            clone.Size = clone.Size - Vector3.new(.2,.2,0)
        end
        clone:Destroy()
    end
end)

https://gyazo.com/e262c4ddec79b0ac8b6d1ababf1a1302 is what i want to happen

0
What is the error line in the code, exactly? :P TheeDeathCaster 2368 — 8y
0
@TheAlphaStigma 19 Senor_Chung 210 — 8y

1 answer

Log in to vote
-2
Answered by
lomo0987 250 Moderation Voter
8 years ago

line 3, change it to

chr = plr.Character

and on line 1 add

repeat wait() until game.Players.LocalPlayer

that or you can just add a wait(2) and it will work perfectly fine!

0
His declarations are valid. He doesn't need to wait until the LocalPlayer is defined. And it's understandable to wait for the character. Redbullusa 1580 — 8y
Ad

Answer this question