I’m making a system the allows you to knock over, and vault pallets.
I’ve came across an issue:
When the player climbs over the pallet, it anchors their character and tweens the Humanoid Root Part, that’s not the issue though, the issue is after the tween or tween(s) finish (for a split second) it sends the player back to the server’s position (mind you this only happens on the other clients not the player vaulting’s client).
I should also clarify, the player activates a proximityprompt which goes to the server and the server
Fires all the clients so its proximity prompt > server> all clients
all you really need to know about the server is this
TweenReplication:FireAllClients(plr, plrHumRoot, TweenOrder, playerAnimation.Animation.AnimationId, self.pallet)
Heres the client script though
local TweenService = game:GetService("TweenService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local TweenReplication = ReplicatedStorage:WaitForChild("RemoteEvents"):WaitForChild("PalletReplication"):WaitForChild("TweenReplication")
local lockInfo = TweenInfo.new(0.3, Enum.EasingStyle.Sine)
local myPlayer = game.Players.LocalPlayer
--THE FUNCTIONS
local function LoadTrack(animationId, animator)
if animationId then
local animation = Instance.new("Animation")
animation.AnimationId = tostring(animationId)
return animator:LoadAnimation(animation)
end
end
local function ModelCollision(model, bool)
for _, part in pairs(model:GetDescendants()) do
if part:IsA("BasePart") and part.Transparency ~= 1 then
part.CanCollide = bool
end
end
end
local function SetAllPrompts(bool)
for i, prompt in pairs(game.Workspace:GetDescendants()) do
if prompt:IsA("ProximityPrompt") and prompt:GetAttribute("Pallet") then
prompt.Enabled = bool
end
end
end
local function CheckSprintAttribute(hum)
if hum:GetAttribute("Sprint") and hum:GetAttribute("Sprint") == true then
return true
else
return false
end
end
local function SetPlayerMovement(bool, playerTurn, hum, humRoot)
playerTurn.Enabled = bool
if bool == false then
hum.WalkSpeed = 0
humRoot.Anchored = true
else
hum.WalkSpeed = 13
humRoot.Anchored = false
end
end
--TWEEN REPLICATION EVENT
TweenReplication.OnClientEvent:Connect(function (plr, targetedPart, targetCFrame, animationId, model)
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local humRoot = char:WaitForChild("HumanoidRootPart")
local playerTurn = char:WaitForChild("SetupScripts"):WaitForChild("PlayerTurn")
local animator = hum:WaitForChild("Animator")
local PalletBarrier = model:FindFirstChild("PalletBarrier")
if PalletBarrier then
PalletBarrier.CanCollide = false
end
local track = LoadTrack(animationId, animator)
if typeof(targetCFrame) == "CFrame" then -- this happens when the player knocks over the pallet
SetPlayerMovement(false, playerTurn, hum, humRoot)
if plr == myPlayer then
ModelCollision(model, false)
end
local tween = TweenService:Create(targetedPart, lockInfo, {CFrame = targetCFrame})
tween:Play() --this tween locks the player in place
task.wait(0.1)
track:Play()
task.wait(0.5)
PalletBarrier.CanCollide = true
SetPlayerMovement(true, playerTurn, hum, humRoot)
if plr == myPlayer then
ModelCollision(model, true)
end
else -- this happens when the player vaults the pallet
if plr == myPlayer then
SetAllPrompts(false)
ModelCollision(model, false)
end
SetPlayerMovement(false, playerTurn, hum, humRoot)
track:Play()
track:AdjustSpeed(0.4)
for i, theCFrame in pairs(targetCFrame) do
if i == 1 then -- 1st tween locks plr in place, 2nd tween moves plr over pallet
local tween = TweenService:Create(targetedPart, TweenInfo.new(0.6, Enum.EasingStyle.Sine), {CFrame = theCFrame})
tween:Play()
tween.Completed:Wait()
else
local tween = TweenService:Create(targetedPart, TweenInfo.new(1.5, Enum.EasingStyle.Sine), {CFrame = theCFrame})
tween:Play()
tween.Completed:Wait()
end
end
if plr == myPlayer then
ModelCollision(model, true)
end
SetPlayerMovement(true, playerTurn, hum, humRoot)
PalletBarrier.CanCollide = true
task.wait(0.2)
if plr == myPlayer then
TweenReplication:FireServer() -- all this does is re-enable the prompts for the server
SetAllPrompts(true)
end
end
end)
Example Video of what’s happening:
if you didn’t notice its at the end of the vault when the players position gets set back