Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

First occurrence of Clone() shows up delayed or not at all?

Asked by 4 years ago
Edited 4 years ago

I have a model located in my ServerStorage. A server script will clone this model when the user presses a key, and the model will move outward from the player using TweenService. For some reason, the first time a player in the game presses the key to clone and move the model, the model doesn't appear until halfway through the tween or sometimes not at all. After this first occurrence, the clone works as expected...

My guess is the model is being cached internally which is why I am only experiencing this on the first occurrence. Has anyone else run into something similar / know of a way to fix this?

The event:

local Workspace = game:GetService("Workspace")
local ServerStorage  = game:GetService("ServerStorage")
local arrow_model = ServerStorage:WaitForChild("Models"):WaitForChild("Arrow")

function getArrowTween(arrow, numBlocks, endPos)

    local arrowTime = (numBlocks * 0.09)

    local arrowInfo = TweenInfo.new(
            arrowTime, 
        Enum.EasingStyle.Linear, 
        Enum.EasingDirection.In, 
        0, 
        false, 
        0
    )
    local arrowProps = { Position = endPos; }
    return TweenService:Create(arrow, arrowInfo, arrowProps)

end

ShootArrow.Event:Connect(function(startPos, endPos, lookDir, color)

    --create arrow
    local arrow = arrow_model:Clone()
    arrow.Parent = Workspace
    arrow.Position = startPos
    arrow.Orientation = Vector3.new(0, orient, -90)
    arrow.Color = color

    --create and play tween
    local arrowTween = getArrowTween(arrow, numBlocks, endPos)
    arrowTween:Play()
    arrowTween.Completed:Connect(function(playbackState)
        if playbackState == Enum.PlaybackState.Completed then
            arrow:Destroy()
        end
    end)

end)
0
Can you paste the script by editing your post? youtubemasterWOW 2741 — 4y
0
updated Hycheese 34 — 4y
0
im thinking of maybe tweening the CFrame instead of Position? Hycheese 34 — 4y

Answer this question