Hi there
I’ve created a prop system allowing you to pick up (hold) props and then drop them. The code is below if you want a more indepth look, but the basics is that when the prop is picked up (handled on the server) a RemoteEvent fires the client. This then triggers a Heartbeat connection which constantly fires the server with the CFrame required for the prop to move to. The server then lerps the prop to that position.
It works well and has no noticeable lag, but the prop itself jitters around the position it’s actually supposed to be in and when released after being held for a long time, it gets flinged miles. Unfortunately, my PC is not good enough to record a good enough video to show you what I mean, but if you need a better look I can provide you with the save.
Server
local Players = game:GetService("Players")
local ServerScriptService = game:GetService("ServerScriptService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local StarterPlayer = game:getService("StarterPlayer")
local StarterCharacterScripts = StarterPlayer.StarterCharacterScripts
local RunService = game:GetService("RunService")
local PropSystem = require(ReplicatedStorage.PropSystem)
local PromptTriggeredEvent = ReplicatedStorage:WaitForChild("PromptTriggered")
local PropThrowEvent = ReplicatedStorage:WaitForChild("PropThrow")
local GivePropPositionCFrame = ReplicatedStorage:WaitForChild("GivePropPositionCFrame")
local Prop = script.Parent
local Prompt = Prop.ProximityPrompt
local Attachment0 = Prop.Attachment0
local IsPropHeld = false
Players.PlayerAdded:Connect(function(Player)
Prompt.Triggered:Connect(function()
if IsPropHeld == false then
IsPropHeld = true
else IsPropHeld = false end
PromptTriggeredEvent:FireClient(Player, IsPropHeld)
end)
end)
GivePropPositionCFrame.OnServerEvent:Connect(function(Player, RequiredPropCFrame)
if IsPropHeld == true then
for i = 0, 1, 0.1 do
wait()
Prop.CFrame = Prop.CFrame:Lerp(RequiredPropCFrame, i)
end
end
end)
Client
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ContextActionService = game:GetService("ContextActionService")
local ServerScriptService = game:GetService("ServerScriptService")
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local TweenService = game:GetService("TweenService")
local PromptTriggered = ReplicatedStorage.PromptTriggered
local GivePropPositionCFrame = ReplicatedStorage.GivePropPositionCFrame
local PropThrow = ReplicatedStorage.PropThrow
local Camera = workspace.CurrentCamera
local PropThrow = false
local IsPropHeld = false
local PropPositionCFrame = Instance.new("CFrameValue")
local RunServiceConnection
local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character
local PropPosition = Character:WaitForChild("PropPosition")
local Motor6D = PropPosition.PropMotor6D
local function OnHeartbeat(dt)
GivePropPositionCFrame:FireServer(PropPosition.CFrame)
end
local function OnPromptTriggered()
if IsPropHeld == false then
IsPropHeld = true
RunServiceConnection = RunService.Heartbeat:Connect(OnHeartbeat)
elseif IsPropHeld == true then
IsPropHeld = false
RunServiceConnection:Disconnect()
end
end
PromptTriggered.OnClientEvent:Connect(OnPromptTriggered)
There are probably a lot of artefacts left over from other attempts at this, sorry about that
Any help is appreciated.