Script cannot detect value

So, every time a player joins the game, a StringValue will be added to their player, to hold the ability that they equipped. The default ability is set to “Cheezburger” when they join the game, and it will change according to the ability they equip. Once the round starts, another script is supposed to run through the players to find the StringValue and clone the item into their backpack from ReplicatedStorage accordingly, but for some reason no matter what ability I equipped, the script always gives me Cheezburger. Why does this happen?

-- Some variables are for other parts of the script, this is the part that clones the ability
local playingTeam = game.Teams.Playing
local timeLeft = game.ReplicatedStorage.Values.Countdown
local roundInProgress = game.ReplicatedStorage.Values.RoundInProgress
local diedEvent = game.ReplicatedStorage.Events.PlayerDied
local countdown = game.ReplicatedStorage.Values.Countdown
local Players = game.Players
local abilities = game:GetService("ReplicatedStorage").Items:GetChildren()

local function ProvideAbility()
	for i, player in playingTeam:GetPlayers() do
		local currentAbility = player:WaitForChild("Ability")
		print(currentAbility.Value)
		for _, ability in abilities do
			if ability.Name == currentAbility.Value then
				local clonedAbility = ability:Clone()
				clonedAbility.Parent = player.Backpack
			end
		end
	end
	task.cancel(abilityTask)
end

roundInProgress:GetPropertyChangedSignal("Value"):Connect(function()
	if roundInProgress.Value == true then
		potatoTask = task.spawn(TagRandomPlayer)
		abilityTask = task.spawn(ProvideAbility)
	end
end)
-- Some things in the script may not look good, I am not very good at scripting ;)
1 Like

If it’s always giving you the default Cheezburger ability, are you changing that StringValue locally? If so, let the server change that value instead of the client.

Yea, I realised that I was changing the value through a local script. Thanks for clarifying! One question - why does local script act like that? In a way that server scripts can’t read, as if only the local script can view it? Once, I had a local script that clones an object and parent it to a player, but the server scripts could not read it.

To avoid exploits. Any changes done locally will not replicate to the server (aside from network owned parts). This is also an advantage to have client-sided visuals and offload server work by letting the client run their own calculations.

You would need to use remotes to establish a 2-way communication with the server and client.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.