I have no idea why my interaction script to collect pumpkins won't work

The script:

script.Parent.Event.OnServerEvent:Connect(function(Player)
	local Mag = (script.Parent.Center.Position-Player.Character.HumanoidRootPart.Position).magnitude
	pcall(function()
		print(1)
		if Mag <= script.Parent.Range.Value then
			if script.Parent.Transparency == 0 then
				print(2)
				Player.leaderstats.Pumpkins.Value = Player.leaderstats.Pumpkins.Value + 1
				local id = tonumber(Player.UserId)
				game.ReplicatedStorage.nnn:FireClient(Player, "song", id, "LUX Events", "Congrats you found a pumpkin! Heres +1 Pumpkins collected", 5)
				script.Parent.Transparency = 1
				wait(100)
				script.Parent.Transparency = 0
			else
				print(3)
				local id = tonumber(Player.UserId)
				game.ReplicatedStorage.nnn:FireClient(Player, "song", id, "LUX Events", "Someone already found this pumpkin, try again later", 5)
			end
		end
	end)
end)

I get no outputs in output.

2 Likes

What is it doing instead of what you want it to do?

Edit: Didn’t see the prints. Which print does it stop at if it does?

2 Likes

Can you show us how the event is fired? If none of your prints are showing up it makes me think that it’s just not getting fired at all. You could also try adding a print at the very top of the function just to be sure if it’s being fired or not.

2 Likes

My interaction works fine on other things. And the script isnt even running

2 Likes

And this is a server script? Other then that I can’t think of much else aside from it not being fired properly from a client.

2 Likes

Try removing the pcall to see if anything errors in there as pcall will silence that and make it hard to find an issue. Also make sure the event is fired and the script is not disabled.

3 Likes

Doesn’t a pcall return the error message? He can grab the error message and warn that if it isn’t working to find out the issue.

2 Likes

Correct. Pcall returns a success Boolean and an error string. To me though I don’t see a reason why he uses pcall for this code though. Another note. returning in a pcall will result in that returned value to become the error string so long the pcall does not fail.

2 Likes

Yeah, I don’t see any issue other than the remote may not be loaded yet. But I’m an idiot so I may be missing something.

2 Likes

As for server side scripts everything should have loaded unless it’s added by other scripts. I just now realized the script seems to be in some kind of folder or something. So op should move the script into somewhere the script will run like ServerScriptService

2 Likes

Oh wait really? So I shouldn’t use :WaitForChild() on most things inside of server scripts?

2 Likes

Nope, should generally not be necessary and I personally never use WaitForChild on the server unless it is a value added by other server scripts.

2 Likes

Nice I didn’t know that :rofl:

2 Likes

This is getting off-topic, But I added the pcall because I was thinking it may be breaking mid-thru

2 Likes

Lol sorry about that, did you check the client in case you may have fired incorrectly, and also checked if the pcall returns any errors?

2 Likes

While checking that also make sure to check if the script is in a place where it will run.

2 Likes

It’s being fired correctly. the script just wont work.

2 Likes

Where is this script located? If you’re certain you’re firing the event properly from a local script then you most likely have the script somewhere it may not run like tobias mentioned.

2 Likes

Heres the source of it.
interactions.rbxm (35.7 KB)

2 Likes

I don’t personally see anything wrong with the setup that would break it but could you try adding a print at the top of the script if you have not? Also print what the pcall returns to see if it breaks at any moment

2 Likes