Remote Event not firing

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? I need the RemoteEvent to fire with the correct parameters.

  2. What is the issue? The RemoteEvent doesn’t fire whatsoever, despite the localscript correctly referencing it and firing the server

  3. What solutions have you tried so far? I’ve looked for many solutions, but no errors appear upon running the script, and I am completely stumped

LocalScript

local buygrenade = Utilities.grenade.Buy
local buybomb = Utilities.bomb.Buy
local buyIED = Utilities.IED.Buy
local buymolotov = Utilities.molotov.Buy
local buylandmine = Utilities.landmine.Buy
local buyflare = Utilities.landmine.Buy
local buyammo = Utilities.ammo.Buy
local buywrench = Utilities.wrench.Buy

buygrenade.MouseButton1Click:Connect(function()
	purchase:FireServer("utilities", "grenade")
        print("Fired Server Successfully!")
end)

Server Script (Both the Event and Script are located in Replicated Storage)

local replicatedStorage = script.Parent

local purchaseEvent = replicatedStorage.purchase

local function purchaseitem(player, category, item)
	local playerAP = player.leaderstats.AP.Value
	print("received an purchase!".. category .. player.. item .. playerAP)

	local Category = replicatedStorage:FindFirstChild(category)
	local item = Category:FindFirstChild(item)

	local Cost = item.Cost.Value

	if playerAP >= Cost then
		playerAP = playerAP - Cost

		local purchaseditem = item:Clone()
		purchaseditem.Parent = player:WaitForChild(category)
	end
end

purchaseEvent.OnServerEvent(purchaseitem)

Scripts do not run in Replicated storage. Put it in server script service or workspace.

If I put it in serverscriptservice, the Client can’t access it, correct?

Yes, but they can access the remote event so there shouldn’t be a need for the client to access the server script, of if there are there should be better alternatives.

I didn’t know they could access remoteEvents inside SSS. Thank you so much man!
(and it has no need to access the scripts. so we’re good.

local replicatedStorage = game:GetService('ReplicatedStorage')
local purchaseEvent = replicatedStorage:FindFirstChild('purchase', false)

local function purchaseitem(player, category, item)
	local playerAP = player.leaderstats.AP.Value
	print("received an purchase!".. category .. player.. item .. playerAP)

	local Category = replicatedStorage:FindFirstChild(category, false)
	local item = Category:FindFirstChild(item, false)

	local Cost = item:FindFirstChild('Cost', false).Value

	if playerAP >= Cost then
		playerAP -= Cost

		local purchaseditem = item:Clone()
		purchaseditem.Parent = player:WaitForChild(category, 10)
	end
end

purchaseEvent.OnServerEvent(purchaseitem)

I know you didn’t ask but here’s a little help with referencing the event in replicated storage and a little update to some of the other things you had. Take what you will and leave what you will

What is the purpose of using FindFirstChild for these. I know it’s useful in some cases but here it is 100% confirmed that the children are there and can be read.

It isn’t quite required because you are right, they are confirmed there but I put them there as a fail-safe to make sure that they are actually there and something didn’t happen. Just out of habit not required but just something I do.

No. Nothing can be replicated from ServerScriptService. Not even RemoteEvents. I guess i’ll just leave it in the Workspace, although it irks me a little bit. Or just keep the event in replicatedstorage, and the script seperate. that works too. I’ve figured it out, all i needed to know

That’s not what they mean…

Leave the event inside of ReplicatedStorage

Then access the event inside of ReplicatedStorage from both scripts. Both client and server can access ReplicatedStorage

2 Likes

already did that. Just confused at first. Thank you both for your help.

1 Like

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