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

Why isn't this spawning?

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

2 comments

0

What is the error line in the code, exactly? :P

0

@TheAlphaStigma 19

1 answer

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!

1 comment

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.

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