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:
- The
Player
instance is loaded. - The contents within
StarterPlayerScripts
are cloned toPlayerScripts
ofPlayer
. - Clicking the referenced part will result in adding value until it hits 5, which is exclusive per player.
- 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)
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!
Use the updated version of the code, if you haven’t already. The other one wasn’t going to work well.
Try this again:
I forgot, localscripts won’t work in workspace
Now try this again:
Also, I had to put it in one script as you couldn’t reward a badge to someone within a local script.
@weakroblox35 Again, I updated the code, if you haven’t already use that one as the other one would just not work well altogether.