What's wrong with my code?

For some reason, there variables in my function are preventing the script from working. (I figured this out with process of elimination). Any idea why?

local event = game:GetService("ReplicatedStorage"):WaitForChild("Folder"):WaitForChild("event")
--this one isn't the problem

event.OnServerEvent:Connect(function(plr)
	local stats = plr:WaitForChild("leaderstats")
	local points = stats:WaitForChild("points")
	
	print("Success") --this doesn't print
	
end)

can you give the code that is sending the event, so that we can understand more…

local player = game.Players.LocalPlayer
local event = game:GetService("ReplicatedStorage"):WaitForChild("Folder"):WaitForChild("event")
local canhit = true

script.Parent.MouseButton1Click:Connect(function()
	if canhit == true then
		canhit = false
		event:FireServer()
		
		task.wait(1)
		canhit = true
	end
end)

It’s a localscript inside of a button in a gui. The server script is inside there as well to change leaderstats

sorry i accidently clicked enter on my last post, but here i have the full one.

I think that because you are using WaitForChild() on an instance that might not be found at any time (usually not the case, but it works preventative), it detects an infinite yield possibility and doesn’t run the rest either.

I got that error, but I haven’t been able to find any solutions that apply to my situation, and most people say it’s not an error just a warning. Any ideas how to fix?

Maybe the solution is to place the server script inside of server
script service instead of having the server script inside of the GUI…

It’s conditional for each button, not really an option

Well I already tested your code, and did what I already said, and it ended up working…

I would also rather format the code something like this:


1 Like

I haven’t found an efficiënt solution, but i usually just place a wait(0.01) so that what I’m trying to get, will be loaded already.

does the leaderstats folder actually exist… because that would be the only possible issue with this. (and would explain the infinite yielding warning)

Must have been a formatting issue then, because the infinite yield warning is gone. Doesn’t need to be moved to serverscriptservice though for my case

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.