Hi guys! The while loop is not working, but everything else works! :( I can't think of any other way to get the while loop to work :/ Any ideas?
01 | local LocalPlayer = game:GetService( "Players" ).LocalPlayer |
02 | local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:wait() |
03 |
04 | LocalPlayer.PlayerModel.PetEquipped.Changed:connect( function () |
05 | if LocalPlayer.PlayerModel.PetEquipped.Value = = "Dog" then |
06 | Pet = game.ReplicatedStorage.Dog:Clone() |
07 | Pet.Parent = Character |
08 | Pet.Name = "Pet" |
09 | Pet.CanCollide = false |
10 | Pet.Transparency = 0.25 -- set transparency |
11 | Pet.Size = Vector 3. new( 2 , 2 , 2 ) --set size here :P |
12 | BodyPosition = Instance.new( "BodyPosition" , Pet) |
13 |
14 |
15 | while wait( 0 ) do |
16 | BodyPosition.Position = Character.Head.CFrame:pointToWorldSpace(Vector 3. new( 2 , 1 , 0 )) |
17 | end |
18 | end |
19 | end ) |
Thanks!
I suggest that you learn to tab and organize your code better.
By just skimming your code, I see a problem with your loop. You're trying to make it fire ever 0 seconds which is impossible. The shortest wait you can do is wait(), you must put a number inside of your wait or put nothing inside. Also, this loop appears to never end. You may want to add and if condition inside that will lead to a break
Okay, Simple fix
01 | local LocalPlayer = game:GetService( "Players" ).LocalPlayer |
02 | local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:wait() |
03 |
04 | LocalPlayer.PlayerModel.PetEquipped.Changed:connect( function () |
05 | if LocalPlayer.PlayerModel.PetEquipped.Value = = "Dog" then |
06 | Pet = game.ReplicatedStorage.Dog:Clone() |
07 | Pet.Parent = Character |
08 | Pet.Name = "Pet" |
09 | Pet.CanCollide = false |
10 | Pet.Transparency = 0.25 -- set transparency |
11 | Pet.Size = Vector 3. new( 2 , 2 , 2 ) --set size here :P |
12 | BodyPosition = Instance.new( "BodyPosition" , Pet) |
13 |
14 |
15 | while true do |
16 | wait() |
17 | BodyPosition.Position = Character.Head.CFrame:pointToWorldSpace(Vector 3. new( 2 , 1 , 0 )) |
18 | end |
19 | end |
20 | end ) |