Help With Raining Candy

Hello, I’m working on a Halloween Event for my game which will have raining candies. I talked to some people in a scripting help Discord server and this is as far as we got.

for i = 1,100 do
	local candy = game:GetService("ServerStorage"):WaitForChild("Candy")
	candy.Position = Vector3.new(math.random(-120,120),100,math.random(-120,120))
	candy:Clone()
	candy.Parent = workspace
end

Output:

It seems that you don’t have the candy object in ServerStorage, as it is not being found. Are you sure you have already places your candy model inside of ServerStorage?

Also, make sure that the model isn’t anchored to that it will fall, unless you want to use another method of falling.

for i = 1,100 do
	wait()
	local candy = game.ServerStorage:WaitForChild("Candy"):Clone()
	candy.Position = Vector3.new(math.random(-120,120),100,math.random(-120,120))
	candy.Parent = workspace
end

The object is in ServerStorage though.
image

Use my script, it should fix it.

That shouldn’t do anything but slow down the script. You only slap in a wait() to prevent infinite loops.

You are right that he needs to :Clone() beforehand though.

It doesn’t seem to give any output error anymore, but nothing is showing.

The rain would look weird probably and just become like waves of candy falling, the wait will make it like actual rain in a certain way.

Hmm, is Candy anchored/invisible?

No it’s not anchored or invisible.

Hey Coldshot_Dev!

If it is yielding infinitely, that means Candy is not a member of ServerStorage. You need to insert the candy instance you want into server storage.

For example:

local candy = Instance.new("Part")
candy.Name = "Candy"
candy.Parent = game:GetService("ServerStorage")

If you have a predefined or placed instance of Candy, make sure it is directly parented to ServerStorage and named Candy. If you are calling on the client, you will not be able to see anything inside ServerStorage as it does not replicate.

If you are needing to do this on the client, I recommend storing the Instance Candy inside ReplicatedStorage.

Hope this helps!

1 Like

Yeah, I was just about to tell him about the replicated storage thing. xd

Are you sure you are using a normal Script, not a LocalScript? Also, where is the script located?

Double also, when you play the game, do you see the Candy object still inside of ServerStorage when you switch to server viewing mode? @Coldshot_Dev

It’s already in ServerStorage as seen in a comment earlier.
image

Yes, the code is in a normal script.

No, it’s no longer in ServerStorage when I switch to view mode.

If you watched to server mode, and it’s still not there, then a Script must be deleting it. Either your own, or a virus script.

Well, it’s parented to workspace when I switch to server mode.

Can’t you just do repeat wait() until game:GetService("ServerStorage"):WaitForChild("Candy")? And then afterwards can’t you do local candy = game:GetService(“ServerStorage”):WaitForChild(“Candy”)?

This probably won’t change anything. The problem is that the Candy part isn’t appearing in ServerStorage after any amount of time.

1 Like