My goal is to have the cash shown in the GIF to tween to the player’s torso in realtime.
If you watch the GIF the tween is behind a little bit.
(sorry for the screen tearing)
I want the tween to actually go to the player’s torso rather than behind the torso or where the player just walked (where it goes)
I’ve tried running the loop bound to stepped (not bindtorenderstep but i had a different function that ran every frame and basically did what is in the for loop but in a different fashion)
Should i be simulating this effect on the client side? What if i want all other players to see the same tween? Wouldn’t i have to replicate it in that case?
My game is a top down shooter like dead ops arcade or smash TV
Do you think i should have cash that drops be local for each player?
My script (a server side script, inside the cashpart instance)
local collectDistance = 8
local canTween = script.Parent.HasOwner --a bool value that states if the cash has a owner or not
local RunService = game:GetService("RunService")
function tweenPartToPlayer(player)
local cashPart = script.Parent
local start = cashPart.Position
for t = 0,1,.1 do
wait()
local rootPart = player.Character:FindFirstChild("HumanoidRootPart")
if rootPart then
local e = rootPart.Position
cashPart.CFrame = CFrame.new(start:Lerp(e,t))
else
script.Parent:Destroy()
end
end
script.Parent:Destroy()
end
RunService.Stepped:connect(function()
local players = game.Players:GetChildren()
for i,v in ipairs(players) do
if v.Character then
local rootPart = v.Character:FindFirstChild("HumanoidRootPart")
if rootPart then
local cashPart = script.Parent
local distance = (cashPart.CFrame.p - rootPart.CFrame.p).magnitude
if distance <= collectDistance then
if canTween.Value == false then
canTween.Value = true
tweenPartToPlayer(v)
end
end
end
end
end
end)
I believe the reason why it appears to tween behind the character instead of directly at the torso is because of latency? What I mean is the server sees a different position than what is on the client, the server hasn’t got the latest position yet. So I don’t think changing the loop would drastically change it.
The only fix I can really think of is to tween the cash to the character and destroy it on the client, but do the actual money collecting on the server.
If you want it to be seen on the other clients you could just run the local script for all cash on all players on each client so it does the same effect, but if they are viewing a different player other than theirs it wouldn’t fix the delay.
The reason it doesn’t tween to the position is because the player moves, then the tween plays. The character will have already changed position in that time and it tweens to the player’s previous position. Try using a Weld (not WeldConstraint) and modifying the C0 value.
Another solution could be to replace e in the lerp function with the root position directly.
I’m assuming this is being done on the server based on the script and as somebody said. To have it go directly to the player’s torso and be smoother, you will want to do it on the client. However, if you still REALLY want to do it on the server (i dont recommend tweening on the server at all unless you use some method like TweenService2) then you can offset it based on the player’s move direction and do it infront of them, basically “guessing” where they’ll be at next and move to there, basically making it looking like its going directly into them, hacky but might work.
TL:DR
Issue is because its being done on server, do tweening on client. Offset with movedirection if you want to do it on server however its hacky.
You could use a RocketPropulsion Object to have it go to the player, and then when the .ReachedTarget event is fired, destroy it and give them the cash.
Did I hear, setting the properties on CartoonFactor, MaxTorque, TurnD and TurnP to make it not rotate towards the player as they’re running and just move it?