String Value in player not updating Value

Hello Devs! if you could give me some advice that would be awesome! please I have been stuck on this for a couple weeks and have been asking around on here but get little feedback

  1. What do you want to achieve?

I want a pet in my inventory to show up when clicking Equip and disappear when clicking again.

  1. What is the issue?

Pretty much have the code already laid out but its not working correctly… no pet shows up when I click equip. the button works fine.

code is a script inside Server Script Service (0 errors in output) :

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I tried moving the script out of Server Script Service but that was no help. Also tried adding a remote event but didn’t code it correctly due to that not working either

1 Like

I don’t think you’ve given enough information for your question to be answered. I don’t even know what the function equip pet does. Please send more code before we can help.

alright my apologizes thanks for reply!
this is my script in Server Script Fully

local player = game:GetService("Players").LocalPlayer

local petModule = require(game.ReplicatedStorage:WaitForChild("PetModule"))
local pet = petModule.chooseRandomPet()

		





local function equipPet(player,pet)
	
	local character = player.Character
	
	if pet ~= nil and character ~= nil then
		
		if character:FindFirstChild(player.Name.."'s Pet") then character[player.Name.."'s Pet"]:Destroy() end
		if character.HumanoidRootPart:FindFirstChild("attachmentCharacter")  then 
			character.HumanoidRootPart:FindFirstChild("attachmentCharacter"):Destroy()
		end
		
		pet.Name = player.Name.."'s Pet"
		
		pet:SetPrimaryPartCFrame(character.HumanoidRootPart.CFrame)
		
		local modelSize = pet.PrimaryPart.Size
		
		local attachmentCharcter = Instance.new("Attachment")
		attachmentCharcter.Visible = false
		attachmentCharcter.Name = "attchmentCharacter"
		attachmentCharcter.Parent = character.HumanoidRootPart
		attachmentCharcter.Position = Vector3.new(1,1,0) + modelSize
		
		local attachmentPet = Instance.new("Attachment")
		attachmentPet.Visible = false
		attachmentPet.Parent = pet.PrimaryPart
		
		local alignPosition = Instance.new("AlignPosition")
		alignPosition.MaxForce = 25000
		alignPosition.Attachment0 = attachmentPet
		alignPosition.Attachment1 = attachmentCharcter
		alignPosition.Responsiveness = 25
		alignPosition.Parent = pet
		
		local alignOrientation = Instance.new("AlignOrientation")
		alignOrientation.MaxTorque = 25000
		alignOrientation.Attachment0 = attachmentPet
		alignOrientation.Attachment1 = attachmentCharcter
		alignOrientation.Responsiveness = 25
		alignOrientation.Parent = pet
		
		
		pet.Parent = character
		
		
	end
	
end


game.Players.PlayerAdded:Connect(function(player)
	
	local equippedPet = Instance.new("StringValue")
	equippedPet.Name = "EquippedPet"
	equippedPet.Parent = player
	
	local inventory = Instance.new("Folder")
	inventory.Name = "PetInventory"
	inventory.Parent = player
	
	
	player.CharacterAdded:Connect(function(char)
		if game.ReplicatedStorage:WaitForChild("Pets"):FindFirstChild(equippedPet.Value) then
			equipPet(player,game.ReplicatedStorage:WaitForChild("Pets"):FindFirstChild(equippedPet.Value):Clone())
			
			end
		end)
	
	 equippedPet.Changed:Connect(function()
		if equippedPet.Value ~= nil then
			if game.ReplicatedStorage:WaitForChild("Pets"):FindFirstChild(equippedPet.Value) then
			equipPet(player,game.ReplicatedStorage:WaitForChild("Pets"):FindFirstChild(equippedPet.Value):Clone())
			
			end
		end
		
		
		
	end)
	
end)

game.ReplicatedStorage.EquipPet.OnServerEvent:Connect(function(player,petName)
	local pet = game.ReplicatedStorage.Pets:FindFirstChild(petName)
	
	if pet and player.PetInventory:FindFirstChild(petName) then
		player.EquippedPet.Value = petName
		
		
		
	end
	
	
end)

game.ReplicatedStorage.UnequipPet.OnServerEvent:Connect(function(player)
	     player.EquippedPet.Value = ""
	if player.Character:FindFirstChild(player.Name.."'s Pet") then
		player.Character[player.Name.."'s Pet"]:Destroy()
	end
	if player.Character.HumanoidRootPart:FindFirstChild("attachmentCharacter") then
		player.Character.HumanoidRootPart:FindFirstChlid("attachmentCharacter"):Destroy()
		
		
	end
	
	
	
end)
1 Like

and like I said I don’t see any errors in output and also Player String Value won’t update when I click on a pet.

I’m still trying to find what the problem is, but I don’t think putting functions like .Changed:Connect(function() would work inside another function.

Please replace this:

game.ReplicatedStorage.EquipPet.OnServerEvent:Connect(function(player,petName)
	local pet = game.ReplicatedStorage.Pets:FindFirstChild(petName)
	
	if pet and player.PetInventory:FindFirstChild(petName) then
		player.EquippedPet.Value = petName
		
		
		
	end
	
	
end)

With this:

game.ReplicatedStorage.EquipPet.OnServerEvent:Connect(function(player,petName)
       print("Equip pet RE triggered")
	local pet = game.ReplicatedStorage.Pets:FindFirstChild(petName)
	if pet and player.PetInventory:FindFirstChild(petName) then
		player.EquippedPet.Value = petName
                print("changed pet name!")
	end
end)

and see if it actually is being triggered

Screen Shot 2020-08-02 at 4.41.10 PM

triggers It yes

It doesn’t look like the second print() triggered, try to make that one trigger by having pet in inventory and replicated storage

manually added It here, and my pets are already stored in Rep Storage. still not seeing the second print

Okay change this

game.ReplicatedStorage.EquipPet.OnServerEvent:Connect(function(player,petName)
       print("Equip pet RE triggered")
	local pet = game.ReplicatedStorage.Pets:FindFirstChild(petName)
	if pet and player.PetInventory:FindFirstChild(petName) then
		player.EquippedPet.Value = petName
                print("changed pet name!")
	end
end)

to:

game.ReplicatedStorage.EquipPet.OnServerEvent:Connect(function(player,petName)
       print("Equip pet RE triggered")
	if game.ReplicatedStorage.Pets:FindFirstChild(petName) ~= nil and player.PetInventory:FindFirstChild(petName) ~= nil then
		player.EquippedPet.Value = petName
        print("changed pet name!")
	end
end)

still won’t fire the second print ()
then I tried a few things like changing petName to pet.Name but no luck.

if helps, I was changing inventory client side before and it didn’t work but when I fire it on server I can get the pet to show up. and also the pet inventory doesn’t show any pets inside server side as well

1 Like