How would i check if intvalue has reached its limit or number?

I’m trying to make a scavenger hunt game, where everytime a player clicks a part the intvalue in starterplayerscripts increases by 1 until it reaches 5 (the limit). How would i approach in checking if the intvalue has reached 5 or not? and if it does fire an event.

1 Like

IntValue.Changed:Connect() would simply be a way to go for it. Alternatively, you can use a conditional directly after the click is done.

1 Like

will this work?

local part = workspace.["Map"].Shelf
local click = part.ClickDetector
local value = script.Parent

click.MouseClick:Connect(function(Player)
	value.Value = value.Value + 1
	
	end)

You should remove the . before “[“Map”]” in:

Also that will only add 1 to the IntValue’s value without checking if it reached it’s limit. If you want to check then do this:

local part = workspace["Map"].Shelf
local click = part.ClickDetector
local value = script.Parent
local Event = --//Path to RemoteEvent

click.MouseClick:Connect(function(Player)
	if value.Value < 5 then
		value.Value += 1
	elseif value.Value == 5 then
		Event:FireClient(Player) 
	end
end)

I tried your solution but the value is not adding up at all when i check it?

Could I get some info on where your script and IntValue is?

image

Is the code in one of those LocalScripts?

Yes it is.
charcharcharkeystrokes

Alright well you’d need to put the code in a regular script for the IntValue’s value to update for both the client and the server. Do that and check the results.

it does change on a normal script but i only want it for the client.

Okay, is this RemoteEvent something you want to fire to the server to?

Yes, it’s an award badge that fires to server, i’ve managed to create a local script that awards the player via remote events

Okay, I’ve got the solution. In your LocalScript put:

local part = workspace["Map"].Shelf
local click = part.ClickDetector
local value = script.Parent
local Event = --//Path to RemoteEvent

click.MouseClick:Connect(function(Player)
	if value.Value < 5 then
		value.Value += 1
	elseif value.Value == 5 then
		Event:FireServer() 
	end
end)

And in your regular Script, you could do:

local BS = game:GetService("BadgeService")
local badgeNumber = --//Badge ID
local Event = --//Path to RemoteEvent

Event.OnServerEvent:Connect(function(plr)
	local hasBadge = BS:GetBadgeInfoAsync(badgeNumber, plr.UserId)
	if hasBadge == nil then
		BS:AwardBadge(plr.UserId, badgeNumber)
	end
end)
  1. Put your value in ReplicatedStorage
  2. Put this script in the ServerScriptService:
local value = game.ReplicatedStorage.Value
game.Players.PlayerAdded:Connect(function(plr)
    value.Parent = plr
end)
  1. Create a script under your value:
local part = workspace["Map"].Shelf
local click = part.ClickDetector
local value = script.Parent
local Event = -- Path for your RemoteEvent

click.MouseClick:Connect(function(plr)
    if value.Value < 5 then
		value.Value += 1
	elseif value.Value == 5 then
		-- Maybe a fireclient event or something else here?
	end
end)

Tell me if this worked out for you!

Nope did not work at all for some reason. Just for clarification there is another localscript script in starterplayer that destroys the part after it gets clicked (this is to prevent any sort of bugs), is it better off to move the part away from map?

I don’t know if you can destroy the part within a local script, plus if you want the output, I don’t think you should put it under starterplayer, try copying that code into a script and put the script under the part.

But since you can’t respond to fireclient with a script, then just put that code where I put:

You can most certainly destroy a part with a local script heres an example:

local part = workspace["Map"].Shelf
local click = part.ClickDetector
click.MouseClick:Connect(function(Player)
	part:Destroy()
end)