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

Why does my loop not work after Character Reset?

Asked by 5 years ago

I’ve encountered an issue with my Pets where-in they don’t seem to move after a reset and insertion of a new model:

My script works by: Inserting the Pet server side, setting Ownership to the Player and managing movement via the client.

So far, after testing I’ve come to realise the issue may be Client based - as without the ‘RenderStepped’ the Humanoid will move to the set Vector, however with it - It will not. Not even while true() works.

Server Code:

local Pets = Instance.new("Folder", workspace)
Pets.Name = "Player_Followers"

local Main = script.Kangop:Clone()

game.Players.PlayerAdded:Connect(function(NewPlayer)

    NewPlayer.CharacterAdded:Connect(function(NewCharacter)

    local Model = Main:Clone()
    Model.Parent = Pets

    local Owner = Instance.new("ObjectValue", Model:WaitForChild("Follower"))
    Owner.Name, Owner.Value = "Owner", game.Players:GetPlayerFromCharacter(NewCharacter)

    NewCharacter:WaitForChild("Humanoid").HealthChanged:Connect(function(Health)
        if Health == 0 then Model:Destroy() else end
    end)

    for _,Parts in pairs (Model:GetDescendants()) do
    if Parts:IsA("BasePart") and Parts.Anchored == false then
    Parts:SetNetworkOwner(game.Players:GetPlayerFromCharacter(NewCharacter))
    else end
    end

    NewPlayer:WaitForChild("PlayerGui"):WaitForChild("Evolyt_Controls").Follow:FireClient(game.Players:GetPlayerFromCharacter(NewCharacter), Model)
    end)

end)

Client Code:

local Main = script.Parent
local Player = game.Players.LocalPlayer
local Player_Followers = workspace:WaitForChild("Player_Followers")

function Animate_Model(Model)
    spawn(function()
    require(Model:WaitForChild("Animate")).Configure()
    end)
end

for _,v in pairs (Player_Followers:GetChildren()) do
    if v then
        if v:IsA("Model") and v:FindFirstChild("Animate") ~= nil then
        if v:WaitForChild("Follower").Owner.Value == Player then
        else Animate_Model(v) end
        else return end
    else return end
end

Player_Followers.ChildAdded:Connect(function(NewChild)
    if NewChild:IsA("Model") and NewChild:FindFirstChild("Animate") ~= nil then
    Animate_Model(NewChild)
    else return end
end)

Main:WaitForChild("Follow").OnClientEvent:Connect(function(Model)

    game:GetService("RunService").RenderStepped:Connect(function()
    print("DERSD")
    end)

end)
0
is your script located in side the pet/character? bountor -5 — 5y
0
Maybe it's cause it failed while trying to find the players character which u can fix by doing if player.character ~= nil then hope this helps thecoolboycool2 18 — 5y

Answer this question