Hello I’m Ryxku and I attempt to make a kind of gravity controller but only on specific parts named “Flottant”. The gravity effects stops when I am not touching the part anymore like jumping or leaving the part.
I use a local script, a remove and server script to try archieve it without lag.
But currently when I touch the part sends me under the map.
I have no idea why it’s a mess by touching the rotation of my humanoidrootpart.
local player = game.Players.LocalPlayer
local PART = script.Parent
local humanoidRootPart = PART:WaitForChild("HumanoidRootPart")
local replicatedStorage = game:GetService("ReplicatedStorage")
local superCoolEvent = replicatedStorage:WaitForChild("SuperCool")
local defaultOrientation = CFrame.new()
local function rotateCharacter(part)
if part.Name == "Flottant" and part:IsA("BasePart") then
local hit = humanoidRootPart.Position - part.Position
local normal = part.CFrame:pointToWorldSpace(Vector3.new(0, 1, 0)) - part.Position
local angle = math.atan2(hit.X, hit.Z)
local newCFrame = CFrame.new(humanoidRootPart.Position, humanoidRootPart.Position + normal)
local rotation = CFrame.Angles(0, angle, 0) * newCFrame
humanoidRootPart.CFrame = CFrame.new(humanoidRootPart.Position) * rotation
else
humanoidRootPart.CFrame = defaultOrientation + humanoidRootPart.Position
end
end
humanoidRootPart.Touched:Connect(rotateCharacter)
If anyone can help me to solve my problem I’ll be happy. I don’t think the problem is from my server script but here you go :
local replicatedStorage = game:GetService("ReplicatedStorage")
local superCoolEvent = Instance.new("RemoteEvent")
superCoolEvent.Name = "SuperCool"
superCoolEvent.Parent = replicatedStorage
superCoolEvent.OnServerEvent:Connect(function(player, rotation)
-- Apply the received rotation to the character
local character = player.Character
if character then
local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
if humanoidRootPart then
humanoidRootPart.CFrame = rotation
end
end
end)