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

Weld C0 CFrame not positioning correctly?

I made this test weld script, and it works great, exactly how I wanted it to be. The problem is that the CFrame of the magic circle is literally on the character, and I want it to be where I said the circle's CFrame is in the script. I tried just circle.CFrame:inverse() but that doesnt work. I cant think of anything else. Can anyone help me? Yes, I know KeyDown is deprecated. I just used it as a quick test for this.

local plr = game.Players.LocalPlayer
local char = game.Workspace:WaitForChild(plr.Name)

local tool = script.Parent
local CAS = game:GetService("ContextActionService")
local Mouse = plr:GetMouse()
local RootPart = char.HumanoidRootPart
local ButtonDown = true
local debounce = false
local animation = script.Animation
local hum = char.Humanoid
local animTrack = hum:LoadAnimation(animation)
function weld()
	if not debounce then
		debounce = true
	
	ButtonDown = true
	
	circle = game.ReplicatedStorage.circle:Clone()
	circle.Size = Vector3.new(10,10,0)
	circle.Parent = game.Workspace.fireball
	circle.Anchored = false
	circle.CanCollide = false
	circle.Transparency = 0
	circle.CFrame = char.HumanoidRootPart.CFrame * CFrame.new(10,0,0)
	local Weld = Instance.new("Weld")
	Weld.Parent = circle
	Weld.Part0 = circle
	Weld.Part1 = char.HumanoidRootPart
	Weld.C0 = circle.CFrame:inverse()*RootPart.CFrame
		bp = Instance.new("BodyPosition")
		bp.Parent = char.Torso
		bp.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
		bp.Position = char.Torso.Position
		bg = Instance.new("BodyGyro")
		bg.D = 100
		bg.Parent = char.Torso
		bg.MaxTorque = Vector3.new(math.huge,math.huge,math.huge)
		
		char.Torso.CFrame = CFrame.new(char.Torso.Position, Mouse.Hit.p)
		while ButtonDown == true do
		bg.cframe = CFrame.new(char.Torso.Position, Mouse.Hit.p)
		animTrack:Play()
		wait()
		end
		wait(2)
		debounce = false
	end
end
Mouse.KeyDown:Connect(function(key)
	key = key:lower()
	if key == "u" then
		weld()
	end
end)
Mouse.KeyUp:Connect(function(key)
	key = key:lower()
	if key == "u" then
		ButtonDown = false
		animTrack:Stop()
		circle:Destroy()
		bg:Destroy()
		bp:Destroy()
	end
end)
	
	

2 comments

0

Well it's on your character because you're using inverse. Could you explain more clearly what you're trying to achieve?

0

Basically, the magic circle is a part that has a magic circle decal on it, front and back. I want it so whenever the player moves their mouse, the character's torso follows, and I want to weld the magic circle to the torso to follow. However, the animation I'm playing is just the characters arm sticking out, and I want the magic circle to be in front of that

1 answer

✓ Accepted answer

There are two problems here.

The first problem is the fact that you're setting Part0 to the circle and Part1 to the humanoid root part. While there is nothing inherently wrong with this, it would be more intuitive (and would make this easier to visualize) to set Part0 to humanoid root part and Part1 to the circle. As a rule of thumb, Part1 is the part you're attaching and Part0 is the part that Part1 is being attached to.

The second problem is the value you're setting to C0. I see what you're trying to do but you're greatly overcomplicating the situation. The way I see it, you want the circle to be offset on the x axis by 10 studs relative to the humanoid root part (assumed because you did circle.CFrame = char.HumanoidRootPart.CFrame * CFrame.new(10,0,0) on line 25). In order to weld the circle to the humanoid root part in that relative position, simply set the C0 to CFrame.new(10,0,0). The C0 represents the cframe to hold Part1 in relative to Part0.

2 comments

0

Thanks a lot! I'm relatively new to scripting and this is my first time actually attempting to use welds to do what I want. Thanks for the additional info and explanations, too

0

No problem

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