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 working?!

So I made a morph, and I'm trying to make an onClick GUI that will make a part called "anim" move. Since the part gets welded to the torso in the morph, if I do a regular CFrame it rotates with the torso, moving the whole player with it. So I made this script to do the touch, although it doesn't repeatable rotate, it just turns a little bit once and never does it again when the GUI is clicked. It would be great if you can tell me why this is happening and fix it.

local player = script.Parent.Parent.Parent.Parent.Parent

function onClick(mouse)
	w1 = Instance.new("Weld")
	w1.Parent = player.Character.Chest.anim
	w1.Part0 = w1.Parent
	w1.Part1 = player.Character.Torso
	while true do
	w1.C0.CFrame = w1.C0.Cframe * CFrame.fromEulerAnglesXYZ(0,1,0)
	wait(0.1)
	end
end

script.Parent.MouseButton1Down:connect(onClick)

1 comment

0

By the way, anim is inside the model called chest if you couldn't already tell.

1 answer

Your script is erroring. Look at the output when you are trying to figure out what is wrong!

C0 and C1 are CFrame values. They don't have a .CFrame property (even if they did, ROBLOX never capitalizes it as Cframe as you have) -- just C0 and C1 is sufficient.

Also, you can use CFrame.Angles instead of CFrame.fromEulerAnglesXYZ -- it's the same method with a much shorter name.


Note that CFrame.Angles uses radians, not degrees. 1 radian is about 57 degrees, which is probably much more than you want.


Also be warned that this script currently allows the user to click repeatedly, which may have strange effects. You should use some sort of debounce or other pattern to prevent multiple of these while loops from running at the same time.

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