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

When you do that it deletes the part for the client, not the server or any other people, plus if you don’t clone the part that you click, when you click it it will have no effect on the IntValue. Are you cloning the part when you destroy it?

1 Like

Fun fact: The solution is actually working but you are not looking in the right place. The item is placed inside a player instance, not StarterPlayerScripts, referring to the first solution.

Nope i am not, just straight up destroying it on the client.
i can move it out of the map if that’s the solution.

But as she’s using a local script, this will only affect the client, which I’m not sure she wants, but if she does want it, then she doesn’t have to turn the localscript into a script.

Exactly, what i’m trying to do is just like egg hunt, add value to player client, and if it reaches 5 then fire an event.

Can I see the code of the LocalScript when you destroy the clickable part?

destroy part localscript

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

ClickDetector.MouseClick:Connect(function(Player)
	part:Destroy()
end)

Its location is in starterplayerscripts.

Here’s what the first solution does:

  1. The Player instance is loaded.
  2. The contents within StarterPlayerScripts are cloned to PlayerScripts of Player.
  3. Clicking the referenced part will result in adding value until it hits 5, which is exclusive per player.
  4. On the 6th click, an event is fired.

Then this should be your script under the value:

local bs = game:GetService("BadgeService")
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
		bs:AwardBadge(plr.UserId, --Badge ID here)
	end
end)

Wait lemme edit that rq, sorry

I don’t think localscripts work in workspace. That’s why i had to put in playerstarter

Here, you could replace that with:

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

click.MouseClick:Connect(function(Player)
    local part = workspace["Map"].Shelf
	local ClonedPart = part:Clone()
	ClonedPart.Parent = workspace["Map"]
	ClonedPart.Name = "Shelf"
	part:Destroy()
end)
1 Like

Try this:

But their objective is to award a badge, not to destroy the part when the value reaches 5.

Yes! this worked thank you!! turns out the problem was destroy() and even better the part disappeared also and yet the value changed! thanks again!

Oh, I’m going to edit my post again.

wait hold on, let me tweak it a bit.

Pretty simple to do actually. Here you go:

local part = workspace:WaitForChild("ClickablePart")
local clickdetector = part:WaitForChild("ClickDetector")
local event = game.ReplicatedStorage.RemoteEvent
local value = script:WaitForChild("IntValue").Value

clickdetector.MouseClick:Connect(function(player)
	if value == 5  then
		event:FireServer("info")
	else
		value += 1
	end
end)

Hope it helps!

1 Like

Use the updated version of the code, if you haven’t already. The other one wasn’t going to work well.

Try this again:

1 Like