I’ve made a character customization area. Basically, whenever you click and hold down on a large button, it moves a “Stage”, which, as a child, has a WeldConstraint with Part0 being the stage and Part1 being a Character’s Torso.
I do not believe the WeldConstraint is the problem, but it could be. It is created on the client, and everything related is in 1 local script.
Basically, the problem right now is that whenever you click, it resets the position of the stage, (and therefore the character as well,) to the orientation that the server sees, always the same place.
Video:
Sorry the contrast is bad, especially in the recording
Script:
--Make move stage button work
local rotateStageButton = characterCustomization.RotateStageButton
local rotateStageButtonHeldDown = false
local mouseStartedDraggingPosition
local stageShouldRotate = false
local stage = game.Workspace:FindFirstChild("CharacterCustomization").Stage
local lastClientRotation
local lastClientFinalRotation = stage.Orientation.Y
rotateStageButton.MouseButton1Down:Connect(function()
print("Pressed")
rotateStageButtonHeldDown = true
mouseStartedDraggingPosition = UserInputService:GetMouseLocation()
print(mouseStartedDraggingPosition.X)
local heartbeat
stage = game.Workspace:FindFirstChild("CharacterCustomization").Stage
heartbeat = RunService.Heartbeat:Connect(function()
print(rotateStageButtonHeldDown)
if rotateStageButtonHeldDown == true and stageShouldRotate == true then
if not stage:FindFirstChild("WeldConstraint") then
local weldConstraint = Instance.new("WeldConstraint")
weldConstraint.Part0 = stage
weldConstraint.Part1 = stage.Parent.CharacterModel:WaitForChild("Torso")
weldConstraint.Parent = stage
stage.Parent.CharacterModel.Torso.Anchored = false
end
if stage and stage.Parent.CharacterModel and UserInputService:GetMouseLocation().X ~= mouseStartedDraggingPosition then
--if UserInputService:GetMouseLocation().X < mouseStartedDraggingPosition.X then
if lastClientRotation == nil then
lastClientRotation = lastClientFinalRotation
else
lastClientRotation = (lastClientFinalRotation - (mouseStartedDraggingPosition.X-UserInputService:GetMouseLocation().X))/250
end
stage.CFrame = CFrame.new(stage.Position.X, stage.Position.Y, stage.Position.Z) * CFrame.Angles(0,lastClientRotation,math.rad(stage.Orientation.Z))
--stage.Parent.CharacterModel:SetPrimaryPartCFrame(CFrame.new(stage.Parent.CharacterModel.PrimaryPart.Orientation.X,stage.Parent.CharacterModel.PrimaryPart.Orientation.Y-mouseStartedDraggingPosition.X-UserInputService:GetMouseLocation().X/100,stage.Parent.CharacterModel.PrimaryPart.Orientation.Z))
--stage.Parent.CharacterModel.HumanoidRootPart.Orientation = Vector3.new(stage.Orientation.X, (stage.Orientation.Y - mouseStartedDraggingPosition.X-UserInputService:GetMouseLocation().X)/100, stage.Orientation.Z)
--elseif UserInputService:GetMouseLocation().X >= mouseStartedDraggingPosition.X then
--stage.CFrame = CFrame.new(stage.Position.X, stage.Position.Y, stage.Position.Z) * CFrame.Angles(0,(stage.Orientation.Y + (mouseStartedDraggingPosition.X-UserInputService:GetMouseLocation().X))/1000,math.rad(stage.Orientation.Z))
--stage.Parent.CharacterModel.HumanoidRootPart.Orientation = Vector3.new(stage.Orientation.X, (stage.Orientation.Y + mouseStartedDraggingPosition.X-UserInputService:GetMouseLocation().X)/100, stage.Orientation.Z)
--end
end
elseif rotateStageButtonHeldDown == false then
lastClientFinalRotation = lastClientRotation
print(lastClientFinalRotation .. " " .. lastClientRotation)
heartbeat:Disconnect()
end
end)
end)
rotateStageButton.MouseLeave:Connect(function()
rotateStageButtonHeldDown = false
stageShouldRotate = false
end)
UserInputService.InputChanged:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseMovement and rotateStageButtonHeldDown == true then
stageShouldRotate = true
end
end)
UserInputService.InputEnded:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
rotateStageButtonHeldDown = false
end
end)
There should be no reading of the stage’s position, except in the beginning before it is possible that it could have been moved, and then that variable never changes to that again.
Thanks for all help!