Okay so, I love it when I see jojo games being made without a overrused script base, lets fix this code and address certain codesmells.
YOU WILL HAVE TO USE ANIMATIONS.
This entire welding process will be simplified and will be fixed by using animations.
Download a animating plugin such as Moon Animator 2, make sure your stand is rigged (motor6ds).
Make sure to make your idle animation loop, I’m going to say it here TWEENS WILL NOT WORK.
local weld = Instance.new("Weld") -- just use a normal weld
weld.Parent = Stand.sHumanoidRootPart -- will be fine
weld.Part0 = weld.Parent -- its okay
weld.Part1 = HumanoidRP -- will work
This code is all fine and dandy, your issue is because you’re using a tween and wait() in your code.
I’m gonna provide you with some basic code that’s gonna fix this issue
-- completely obliterate the tweening here:
local standWeld = Instance.new("Weld")
standWeld.Part0 = HumanoidRP -- I've done the favor of making these your variable names
standWeld.Part1 = Stand.sHumanoidRootPart -- notice how im doing the properties first and not the parenting
-- this fixes replication lag is what happens if you do the reverse
standWeld.Parent = HumanoidRP
local idleTrack = Stand.sHumanoid:LoadAnimation(addYourIdleAnimHere) -- im assuming your stand has a Humanoid,
-- if it doesn't use an AnimationController object
idleTrack:Play() -- if this has a: LoadAnimation requires the Humanoid object to be a descendant of workspace error,
-- ill let you fix that
Alright, so this should fix your problem, another thing you mentioned is that you rather use a tween, this will look like a tween aswell, it wont appear staticly at the stand user’s back, it’ll smoothly move towards it.
EXTRA CODE SMELLS.
Code smells are basically pieces of code that indicate a bigger problem, lets get some things down.
spawn() and wait() are so unreliable, they should NEVER be in production code (aka the game)
So what’s the solution? The gold mine of a service, game:GetService("RunService")
.
FIXING WAIT.
We can easily fix up wait() by replacing it with a efficient function in our code,
Here’s a solution.
local function wait(n) -- local function will override wait()
n = n or 0.01 -- this is a nifty code trick that replaces if X == nil then statements
local heartbeat = game:GetService("RunService").Heartbeat -- heartbeat is widely used in coding, it's way more reliable
local elapsedTime = 0 -- counter for the amount of time has passed since calling wait()
while elapsedTime < n do
local addThisToElapsedTime = heartbeat:Wait() -- heartbeat returns a delta (change in value if you dont know) that represents the elapsed time
-- this also accounts for server lag!!
elapsedTime = elapsedTime + addThisToElapsedTime
end
end
Wow, that was alot, but I’m sure you can inform yourself by reading the comments.
FIXING SPAWN.
This one is really touchy. I’ve made a jojo game with spawn() handling stands, it. never. works.
So how do we even fix this?
We use something sort of expensive, a coding technique called fastSpawn
This works by using BindableEvents, they let you assign code to be executed when it’s fired, like
a remote event, but just for individual scripts.
So how do we implement this in code? Look.
local function spawn(func) -- again we overwrite just fine with local function
local bindEvent = Instance.new("BindableEvent") -- create our event
bindEvent.Event:Connect(func) -- assign our code to the event with :Connect()
bindEvent:Fire() -- this executes the code IMMEDIATELY. which is why its expensive.
bindEvent:Destroy() -- we do not need it anymore at all!!
-- done.
end
Another hefty one, but the comments will help you entirely. NOW. I want to tell you something ESPECIALLY WITH JOJO GAMES. Do not. DO NOT. Make remotes for client-authorative stands.
“What do you mean?” you ask puzzled.
This is my biggest pet peeve, in the source code of A Bizarre Day, it uses client-authorative stands, this is so SO unsecure, it’s not okay to do this in production games. ABD also lets you supply hit sounds, so this isnt a matter of security aswell, it’s a matter of censoring bypassed hit sounds aswell.
What’s an example of this? Remotes like: “Damage1, Damage2, Spawn, etc…” Always have the server process this, I’m sure you can come up with a thing on your own.
SO? WHAT ELSE?
Nothing, good luck on your game, and be unique, dont have a game loop of roka, arrow, roka, arrow, GOOD STAND GOTTA TRADE IT, roka, arrow.
EDIT:
Also, you should completely replace your summon remote event with the .CharacterAdded event on Player. This can be spammed by exploiters, and adding a debounce as an argument will not work, you’re trusting the client faithfully, DONT TRUST THE CLIENT EVER EVER.