Need help with my pet boost script

Hello,
I’m currently trying to add pet boosts to AlvinBlox’s egg hatching system, what i did is adding an IntValue to the pet and names it boost
boost
then in my tool script i wrote this:



local currentValue = script.Parent.SlashesIncrease.Value
local function onValueChanged()
	local newValue = script.Parent.SlashesIncrease.Value
	currentValue = newValue
end 
script.Parent.ActivateTool.OnServerEvent:Connect(function(plr)
	local Slashes = game.Players[script.Parent.Parent.Name].leaderstats.Slashes
	
	script.Parent.SlashesIncrease.Value = script.Parent.SlashesIncrease.Value * plr.EquippedPet.PetBoost.Value
	script.Parent.SlashesIncrease:GetPropertyChangedSignal("Value"):Connect(onValueChanged)
	Slashes.Value = Slashes.Value + script.Parent.SlashesIncrease.Value + plr.leaderstats.Upgrades.Value
	
end)


then i added an IntValue to the player here is what it looks like:

Imageboost

then i added a script to serverscriptservice and i wrote this:

  while wait(.2) do
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
if character:FindFirstChild(player.Name.."'s Pet") then 

	player.EquippedPet.PetBoost.Value = character:FindFirstChild(player.Name.."'s Pet").Boost.Value
		 		
else
	player.EquippedPet.PetBoost.Value = 1
end

end

but it doesn’t update his PetBoost value however when i change it myself from the server it give the boost

Thank you!

2 Likes
local player = game.Players.LocalPlayer 

can only be done from a local script and not a ServerScript, you must get the player some other way depending on what you need.

1 Like

oh okay thank you! i will try fixing it

1 Like

I’m trying to explain this as easy as possible but Changing the script to a LocalScript won’t work either because LocalScripts don’t function when they are on the server side since they are ‘Local’ they only function for the client/ the player.

1 Like

oh thank you but is there a way to get the player from a normal script?

1 Like

You can use a remote event and do FireAllClients, and on a local script do OnClientEvent. Or, do

      for _, player in pairs(game.Players:GetPlayers()) do
             -- stuff
      end
1 Like

In my opinion the best way for you to get the player would be is to get PlayerFromCharacter // That should help you with what you need>

2 Likes