Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Script reading boolean value as true when it is false?

I'm making a shop and one of the items is a speed boost that lasts for one life. Once you click to spawn in, the script checks if the "speedpower" boolValue is true or false. If it is true, it gives you high speed and changes the value to false. The shop will not let you buy the speedpower if you already have it. However, if you die and no longer have the boolValue set to true, the script will still not let you buy it and reads that the value is True, even though it is false. Here is the Script

game.ReplicatedStorage.RemoteEvents.SpeedUpEvent.OnServerEvent:Connect(function(player)
	local money = player.leaderstats.Money
	local speedpower = player.powerstats.speedpower
	if money.Value >= 5 then
		print("Not Broke")
		if speedpower.Value == false then
			money.Value = money.Value - 5
			speedpower.Value = true
		else
			print("Already Active")
		end
	else
		print("Broke")
	end
end)

This is the other function, which fires when a menu button is clicked. It is in a local script, would this be the problem?

	if powerstats:WaitForChild("speedpower").Value == true then
		player.Character.Humanoid.WalkSpeed = 30
		powerstats:WaitForChild("speedpower").Value = false
	else
		player.Character.Humanoid.WalkSpeed = 16
	end

3 comments

0

Can you post all the scripts involving this speed powerup?

0

Maybe the value is set to false localy, and the server still thinks its true

0

btw, I just set it to trigger a remoteEvent into a server script, and it still does the same thing. In players, it says the value is false, but the buy function still thinks it's true.

1 answer

✓ Accepted answer

If you're changing the BoolValue on the client and reading it from the Server, you're going to encounter issues with Filtering Enabled

(you can read up more about it in this scriptinghelpers post)

basically, you can't use line 3 in your code

-- line three
powerstats:WaitForChild("speedpower").Value = false

.. because you are changing the BoolValue locally, which will not be replicated by the server

what you need to do instead is you can either:

  • change the localscript to a script (if possible)
  • ask the server to change the value for the client (sending a request via a remoteevent)

hope this helps :)

This discussion is preserved as it was. New answers, comments, and votes are closed.