Candy Scavenger Hunt Not Working

Keep in mind that it should be a localscript, and can I see the code?

Heres what I Have them set up as
Screen Shot 2020-10-17 at 12.01.58 PM

I have the candies all stored in a folder in workspace
then in ServerScriptStorage I have a normal script to detect if touched
Screen Shot 2020-10-17 at 11.08.00 AM
which fires the FoundCandy remote event (which is in rep storage)

that then triggers the local script inside of the guI

are u saying both need to be local if so where do I move the one in ServerScript to?

You’re checking if player is true, which is never as the player variable is the player.

Keep in mind :FireClient needs a player parameter to know which client should be fired.

Just check if plr isn’t nil, by doing the following:

if plr ~= nil then

Also, you’re only doing this on 1 candy. If you want all candies to do this, just use a for loop to loop through all candies and run the code.

1 Like

The .Touched:Connect funtion should be a localscript under the candy mesh.

1 Like

No, it should not. Firing clients must be done on the server. To be honest, you can just do the entire script in 1 local script if you only want it to display that they found the candy.

The entire code detecting that it’s being touched, then firing a Fireclient should be in the mesh.

Keep in mind localscripts do not run in workspace. They only run when they are descendant of the player, in a tool, or in the players character, or replicatedFirst.

You’re able to bypass this by the help of a script. ^^

wait where does the for loop part go?

You wanted the candy to disappear for the player who touches it, but still be visible to everyone else, correct?

yes cause each player is doing the quest separately

its currently not even detecting that im hitting it tho

Join this place for a second: test - Roblox

k im there in the game now (words)

ontouchthing.rbxl (27.0 KB)

Here’s a copy of the place. You’ll have to open the circle called “Part” in workspace, then check Script, and the underlying LocalScript inside of the Script to check out how it’s done.

If you have any other questions, then feel free to ask.

1 Like

Side note: You can change how long the LocalScript remains active, this can be changed in line 23 in the Script under Part.

wait so do I put this into each candy then?

1 Like

Correct. I recommend finalizing the whole script for the candy bar, before making replicates of it.

If you’re wanting to make randomized spawning candies, you should grab a copy of the script in the Part → place it in any form of folder to save it. To do the randomized cloning of new candies, you should use Instance.new(), and configure it however you want to. Once done, and you’ve made them spawn randomly, you can meanwhile it’s creating the part, take a copy of the Script (+ LocalScript inside), and change its’ parent to the new part you’ve made.

1 Like

It worked thank you so much! (space)

1 Like

You’re welcome. I’ve written a randomized candy spawner code, which i recommend putting in ServerScriptService. Feel free to use it.

Size can also be changed btw.

while true do

local thing = Instance.new("Part")
thing.Anchored = false
thing.Name = "Candy"
thing.Parent = workspace
thing.Position = Vector3.new(math.random(-50,50),math.random(5,10),math.random(-50,50)) 
thing.Shape = Enum.PartType.Ball
thing.Color = Color3.fromRGB(math.random(0,255),math.random(0,255),math.random(0,255))

wait(1)
end