local RS = game:GetService("ReplicatedStorage")
local Event = RS.HotPotatoSelected
local Start = RS.GUIEvents.SecondEvent
Event.OnServerEvent:Connect(function()
local Players = game.Players:GetPlayers()
local random = Players[math.random(1,#Players)]
Start.OnServerEvent:Connect(function()
game.Workspace.Potato.Position = random.Character.HumanoidRootPart.Position
workspace.Potato.Parent = random.Character.HumanoidRootPart
while true do
random.Character.HumanoidRootPart.Potato.Position = random.Character.HumanoidRootPart.Position + Vector3.new(0,0,0)--The Vector3 appears to do nothing but without it, the potato is offset
wait()
end
end)
end)
The potato’s position is constantly updated to be at the position of the selected player’s HumanoidRootPart. But the model is always lagging behind and doesn’t move perfectly with the player. Is there a better method of doing what this code does so the model doesn’t lag behind?
It seems that every time Event is fired, more connections is made to Start. The following code block is for analysis only. Other than that, I’m telling you that the lag is always there. Why are you making the potato follow a player’s character?
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = ReplicatedStorage.HotPotatoSelected
local Start = ReplicatedStorage.GUIEvents.SecondEvent
Event.OnServerEvent:Connect(function()
-- Anyone could fire this and continue operations...
local players = Players:GetPlayers()
local random = players[math.random(#players)]
Start.OnServerEvent:Connect(function()
-- Refer to the previous comment
-- This event will always target the same player it first randomly chose lol
-- and there is only one potato at a time
workspace.Potato.Position = random.Character.HumanoidRootPart.Position
workspace.Potato.Parent = random.Character.HumanoidRootPart
while true do
-- This will never stop
random.Character.HumanoidRootPart.Potato.Position = random.Character.HumanoidRootPart.Position + Vector3.new(0,0,0)--The Vector3 appears to do nothing but without it, the potato is offset
task.wait()
end
end)
end)
I’m making the potato follow the character because I want it to appear like they’re a giant potato, but I want to keep the model of the player intact because I will later make it so that the potato model is transferred from player to player. Should the potato be more of something like a hat that is put on the player?
Consult the documentations first before you ask. It’s generally anything that acts and looks like a part. Unions are example that can be unions. Check with this:
Everything worked as intended, except for one thing. The potato is rotated the wrong way. When I tried setting the handle’s orientation, I got an error message saying: Orientation is not a valid member of MeshPart “Potato.Handle”.
Oh yeah, I forgot about something. Keep playing around with the placement of the attachment. Its orientation and relative position to the handle matters!
Or just put one on a dummy, run the game, adjust the values on the accessory on the dummy and then copy those properties.