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

Why does this teleport around me when I try to angle it?

Asked by 7 years ago

I'm trying to make a gun, and I've decided making fake arms is the best way to animate it. I've created the fake arms, but whenever I try to angle them, it sets the rotation to what I would think it's supposed to set it to, but it then teleports it around my character. Does anyone know why this is happening and wouldn't care to explain?

Here's my script for making the fake arms (yes, this is a localscript)

local player = game:GetService("Players").LocalPlayer
local character = player.CharacterAdded:wait()
local rightArm,leftArm = character:WaitForChild("Right Arm"),character:WaitForChild("Left Arm")
local rightWeld,leftWeld = Instance.new("Weld",character:WaitForChild("Torso")),Instance.new("Weld",character:WaitForChild("Torso"))
local fakeArms = Instance.new("Model",character)
local fakeRightArm,fakeLeftArm = Instance.new("Part",fakeArms),Instance.new("Part",fakeArms)
fakeArms.Name = "fakeArms"
rightWeld.Name = "rightWeld"
fakeRightArm.Size = rightArm.Size
fakeRightArm.CFrame = rightArm.CFrame
fakeRightArm.CanCollide = false
rightWeld.C0 = character:WaitForChild("Torso").CFrame:inverse()
rightWeld.Part0 = character:WaitForChild("Torso")
rightWeld.C1 = fakeRightArm.CFrame:inverse()
rightWeld.Part1 = fakeRightArm
leftWeld.Name = "leftWeld"
fakeLeftArm.Size = leftArm.Size
fakeLeftArm.CFrame = leftArm.CFrame
fakeLeftArm.CanCollide = false
leftWeld.C0 = character:WaitForChild("Torso").CFrame:inverse()
leftWeld.Part0 = character:WaitForChild("Torso")
leftWeld.C1 = fakeLeftArm.CFrame:inverse()
leftWeld.Part1 = fakeLeftArm

Here's the script that I've tried to angle the arms workspace.Player1.Torso.leftWeld.C0 = workspace.Player1.Torso.leftWeld.C0 * CFrame.Angles(1,0,0)

Thanks to anyone that can help :)!

0
What do you mean by teleporting it around your character? And also, if you want to use degrees for the rotation, you must use math.rad(1) rather than 1 in the CFrame.Angles. Also, you are not removing the real arms, or making them transparent. brianush1 235 — 7y
0
Sorry for taking so long to respond. I was going to create a gif, but I was waiting for it to upload, then I realized it had already uploaded and I didn't know it. Here's what happens when I use the script I put (but I changed CFrame.Angles(1,0,0) to CFrame.Angles(math.rad(10),0,0) so you could see the difference better) http://i.imgur.com/lnFU2hb.gifv NewVoids 97 — 7y
0
Can anyone help me? NewVoids 97 — 7y
1
If is is a local script then all variables will be local. I don't think you need to tell the script that the variables are local. Jexpler 63 — 7y
View all comments (2 more)
1
That's not what local means. Defining variables as local means they'll have a local scope and can't be accessed outside of that current scope. And yes, the local isn't required there but I think it looks nicer lol NewVoids 97 — 7y
0
Local values are also read faster by the lua compiler. RubenKan 3615 — 7y

Answer this question