Fixing Polarisprog's Simulator Script

Hello there Developers!

I was scrolling down on Youtube and found @polarisprog 's video
and i was so impressed and i tried to follow it, and Copied the Code…It doesn’t work can anybody review my code?

DataScript:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local DataStoreService = game:GetService("DataStoreService")

local PlayerData = ServerStorage.PlayerData
local Shared = ReplicatedStorage.Shared
local ServerModules = ServerStorage.ServerModules

local FormatNumber = require(Shared.FormatNumberAlt)
local PetModule = require(ServerModules.PetModule)

local function NewPlayer(Player)
	for _, instance in pairs(PlayerData:GetChildren()) do
		local cloned = instance:Clone()
		cloned.Parent = Player
	end
	
	local PetFolder = Instance.new("Folder")
	PetFolder.Name = Player.Name
	PetFolder.Parent = workspace.Pets
	
	local StatsFolder = Player.Stats
	local Leaderstats = Player.leaderstats
	
	for _, val in pairs(StatsFolder:GetChildren()) do
		Leaderstats:FindFirstChild(val.Name).Value = FormatNumber.FormatStandard(tonumber(val.Value))
		val.Changed:Connect(function()
		Leaderstats:FindFirstChild(val.Name).Value = FormatNumber.FormatStandard(tonumber(val.Value))
	 end)
	end
	
	task.wait(5)
	
	PetModule.EquipPet(Player, "Pet [1]")
end

local function PlayerLeaving(Player)
	if workspace.Pets:FindFirstChild(Player.Name) then
		workspace.Pets:FindFirstChild(Player.Name):Destroy()
	end
end

Players.PlayerAdded:Connect(NewPlayer)
Players.PlayerRemoving:Connect(PlayerLeaving)

PetModule:

local module = {}

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Pets = ReplicatedStorage.Pets

function module.EquipPet(Player, PetName)
	local PetModel = Pets:FindFirstChild(PetName):Clone()
	if PetModel then
		PetModel = PetModel:Clone()
		PetModel.Parent = workspace.Pets:FindFirstChild(Player.Name)
		if Player then
			local Character = Player.Character
			if Character then
				if not Character.HumanoidRootPart:FindFirstChild("PetAttachments") then
					local PetAttachments = Instance.new("Folder")
					PetAttachments.Parent = Character.HumanoidRootPart
				end
				local PetAttachments = Character.HumanoidRootPart:FindFirstChild("PetAttachments")
				if PetAttachments then
					local att1 = Instance.new("Attachment")
					att1.Name = "Attachment1"
					att1.Position = PetModel:FindFirstChild("AttachmentPosition").Value
					att1.Parent = Character.HumanoidRootPart

					local att0 = Instance.new("Attachment")
					att0.Name = "Attachment2"
					att0.Parent = PetModel.PrimaryPart
					
					local AlignPosition = Instance.new("AlignPosition")
					AlignPosition.Attachment0 = att0
					AlignPosition.Attachment1 = att1
					AlignPosition.RigidityEnabled = false
					AlignPosition.MaxForce = PetModel.MaxForce.Value
					AlignPosition.Responsiveness = PetModel.Responsiveness.Value
					AlignPosition.Parent = PetModel.PrimaryPart
					
					local AlignOrientation = Instance.new("AlignOrientation")
					AlignOrientation.Attachment0 = att0
					AlignOrientation.Attachment1 = att1
					AlignOrientation.RigidityEnabled = false
					AlignOrientation.MaxForce = PetModel.MaxForce.Value
					AlignOrientation.Responsiveness = PetModel.Responsiveness.Value
					AlignOrientation.Parent = PetModel.PrimaryPart
					
					game:GetService("RunService").Heartbeat:Connect(function()
						att0.Position = PetModel.AttachmentPosition.Value
						AlignPosition.MaxForce = PetModel.MaxForce.Value
						AlignOrientation.MaxTorque = PetModel.MaxForce.Value
						AlignPosition.Responsiveness = PetModel.Responsiveness.Value
						AlignOrientation.Responsiveness = PetModel.Responsiveness.Value
					end)
		      end
		  end
	  end
   end
end


function module.UnEquipPet(Player)
	
end

function module.UnequipAllPets(Player)
	
end

return module

**Can anyone Review the code pls, The pet won’t show up.

Btw this is the Screenshot of my Test Pets:

I placed the Pets Folder where this pets are stored and tried to test them, It doesn’t work

1 Like

First: Check console. Maybe function/if-end blaces are in incorrect format.

It’s all clear let me send you a screenshot:

see?

Print to check function is actually called or not

Well, The prints worked but idk why the pets won’t show up
Screenshot:
weg3gef

Maybe pet’s position, visibility, anchored or not…

1 Like

Ok let me try it out, Thanks @AceBookMarker

It still doesnt work, Its getting really annoying

Please review the code guys i really need it

	if PetModel then
		PetModel = PetModel:Clone()
		PetModel.Parent = workspace.Pets:FindFirstChild(Player.Name)
		if Player then

This can be

	if PetModel and Player then
		PetModel = PetModel:Clone()
		PetModel.Parent = workspace.Pets:FindFirstChild(Player.Name)
2 Likes

And:

also, Better not be from a YouTube tutorial. Those videos get outdated quickly, you’ll end up learning bad scripting habits.
Code From A Tutorial Not Working - #3 by Prototrode

2 Likes

Thank you so much @AceBookMarker and btw it worked

1 Like