I made a shop system but the only thing is when a the pet model is cloned in the player’s inventory the server script won’t work. The server script inside of the pet checks if the boolvalue in the model has been updated to fire the script the rest the script.
I got this script off youtube to make the pet pop up so I’m not sure if it works but I added the part to check if the equipped value is true or not.
local pet = script.Parent
local plr = script.Parent.Parent.Parent
function givePet (player)
if script.Parent.Equipped.Value == true then
local character = player.Character
if character then
local humRootPart = character.HumanoidRootPart
local bodyPos = Instance.new("BodyPosition", pet)
bodyPos.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
local bodyGyro = Instance.new("BodyGyro", pet)
bodyGyro.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
pet.CanCollide = false
while wait() do
bodyPos.Position = humRootPart.Position + Vector3.new(4.5, -0.9, 1.5)
bodyGyro.CFrame = humRootPart.CFrame
end
end
end
end
script.Parent.Equipped.Changed:Connect(function(player)
print("FiredPetEquip")
if script.Parent.Equipped.Value == true then
givePet(player)
end
end)
Thank you! The only thing is the script just isn’t firing at all that’s why I posted this. I redid the script but just had it in the workspace and it worked, but the issue is that the script isn’t firing or doing anything when it is cloned into the player after they purchase it.
Theres a really cool way to check where is the problem in a script that’s not doing something. Put print(xyz)s after everything, like every if statement, after the function, etc. Make all of them have a different output, run it, and you’ll see where the problem is (where the print didn’t print).
And the reason all 3 of us tried modifying the loop is that usually, the reason why a script doesn’t run is that it’s stuck in a loop inside it.
Also, is the script disabled before cloning? If not, disable it. Then enable the clone after you put it in the player. Every script should be disabled before cloning. This could fix it
Hope it works
Never mind it still dosent work. I made it so when you buy the item it will enable the scripts and that part works just the scripts dont work. I even tested this by adding a print in a script that gets enabled and it dosent print when it is enabled. I’m so confused why it isn’t working.
I cant see a problem here. it should work. Can I see the EnableScripts too? Maybe I can find something there
Also, I think it would be better to clone these things inside the player’s character or the backpack, not the Player instance itself. But if the other scripts work (the Codes and Gamepass and such), it should work too I guess
Everything else works so I’m not sure why it does it either. Inside the script it is just a print(“Enabled Worked”) so I could test to see if it works.