Hi there
I’m trying to make a prop system, similar to the one in the Source engine, where the prop is in front of the player’s camera when held. The problem is the prop does not move when I attempt to lerp it to the required position in front of the player’s camera. I have two scripts here, PropHandler which is a ServerScript under the prop itself, and PropService which is a ModuleScript which does most of the stuff.
PropHandler:
local Players = game:GetService("Players")
local ServerScriptService = game:GetService("ServerScriptService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PropService = require(ServerScriptService.PropService)
local Prop = script.Parent
local Prompt = Prop.ProximityPrompt
local Attachment0 = Prop.Attachment0
local PropHeld = false
Prompt.Triggered:Connect(function()
-- this handles the immediate triggering of the prompt
if PropHeld == false then
PropHeld = true
PropService.PropPickup(Prop, Attachment0)
elseif PropHeld == true then
PropService.PropDrop(Prop)
PropHeld = false
end
end)
while PropHeld == true do
-- this handles the constant update of the prop's position in line with the camera
task.wait()
PropService.PropHeld(Prop)
end
PropService:
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local RunService = game:GetService("RunService")
local ContextActionService = game:GetService("ContextActionService")
local PropHeld = false
local AssignMouseButtonPropThrow = Enum.UserInputType.MouseButton1
local Camera = workspace.CurrentCamera
local VectorForce = script.VectorForce
local PropService = {}
function PropService.PropPickup(Prop, Attachment0)
-- This does stuff to do with prop throwing, but without that it does nothing.
-- I've left it here so you can understand the proximity prompt stuff.
end
function PropService.PropHeld(Prop)
local CameraCFrame = Camera:GetRenderCFrame()
local RequiredPropCFrame = CameraCFrame * CFrame.new(0, 0, -5)
for i = 0, 1, 0.1 do
Prop.CFrame = Prop.CFrame:Lerp(RequiredPropCFrame, TweenService:GetValue(0, Enum.EasingStyle.Cubic, Enum.EasingDirection.InOut))
end
end
function PropService.PropDrop(Prop)
Prop.CFrame = Prop.CFrame
end
return PropService
I’ve removed everything about throwing the prop as that is completely irrelevant and operates almost separately to the rest of the system.
Not entirely sure why the prop doesn’t move, no errors are given and the scripts look correct to me.
Any help is appreciated
Thanks