[SOLVED] Remote events not working?

I was making when a player touches a part the frame would be visible but its apparently not working?

Server Script

for i,ShopBuyParts in pairs(BuyShop:WaitForChild("ShopPad"):GetChildren()) do


	ShopBuyParts.Touched:Connect(function(Hit)



		if ShopDebounce == false then
			ShopDebounce = true

			local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
			if Player then
                               
				RemoteEvents.BuyingEvent:FireClient(Player)
                print("Fired Remote Event")

			end
			task.wait(2)
			ShopDebounce = false
		end
	end)
end

Local Script

RemoteEvents.BuyingEvent.OnClientEvent:Connect(function(Player)

	ShopFrame.Visible = not ShopFrame.Visible
end)

It also prints after I fired the Remote Event but doesn’t pick up on the client

1 Like

I think this is just a bug in Roblox. I don’t know what to tell you…

1 Like

I tried restarting studio but it also didn’t work.

1 Like

Oof…give me some time. I bet I can figure out the problem.

1 Like

Can you add a print in the remote event (client) itself?

1 Like

I tried that and it didn’t print for some reason

1 Like

So it prints “Fire Remote Event”, but it does not print inside the .OnClientEvent()?

Try removing the Player variable

RemoteEvents.BuyingEvent.OnClientEvent:Connect(function(Player)
-- Should be this:
RemoteEvents.BuyingEvent.OnClientEvent:Connect(function()

Since the Player sent on the server is “consumed” by the RemoteEvent

4 Likes

If removing the “Player” variable doesn’t work then can you do:

print(RemoteEvents.BuyingEvent:GetFullName()) to check if they are in the same location? (For both server and client)

1 Like

It worked! Thanks for your help once again :smiley:

2 Likes

Why would a variable stop it from firing though? Do you have anything in mind of why this would happen?

1 Like

I am honestly surprised that worked. I didn’t think that would solve it, was just aimed at code readability (no sense marking that you will receive a variable you don’t want to receive)

2 Likes

Uh, It stopped working…
What???
Edit: Ill send a vid that it isn’t working. But it was though this is weird

1 Like

Can RunService stop it from firing?
Because its not working now

Sometimes its working and sometimes not

1 Like

image

It may be another thing, I tried it and this worked:

Server:

task.wait(5);
game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent"):FireClient(game:GetService("Players"):GetPlayers()[1]);

Client:

game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent").OnClientEvent:Connect(function(Player)
	print("Nice!");
end);
1 Like

Depends on how you use it, can you send the code where you use it?

1 Like

This is the Local Script


local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")




local Player = game:GetService("Players").LocalPlayer
local Mouse = Player:GetMouse()
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid") 


local RemoteEvents = ReplicatedStorage:WaitForChild("RemoteEvents")
local ShopItemsStats = ReplicatedStorage:WaitForChild("ShopItemsStats")


local Map = game.Workspace.Map


local Shops = Map:WaitForChild("Shops")
local BuyShop = Shops:WaitForChild("BuyShop")
local SellShop = Shops:WaitForChild("SellShop")


local Plots = Map:WaitForChild("Plots")

local MainGui = Player.PlayerGui:WaitForChild("MainGui")

local ShopFrame = MainGui:WaitForChild("ShopFrame")
local SeedsFrame = MainGui:WaitForChild("SeedsFrame")





local ShopScrollingFrame = ShopFrame:FindFirstChild("ShopScrollingFrame")  
local BuyingItemFrame = ShopFrame.BuyingItemFrame





local BuyItemButton = BuyingItemFrame:FindFirstChild("BuyButton")






RemoteEvents.BuyingEvent.OnClientEvent:Connect(function()
	
	print("Working..")
	ShopFrame.Visible = not ShopFrame.Visible
end)







local ItemDebounce = true




for i,Item in pairs(ShopItemsStats:GetChildren()) do



	local ItemButton = Instance.new("ImageButton")
	ItemButton.ScaleType = Enum.ScaleType.Fit
	ItemButton.BackgroundColor3 = Color3.new(1, 0.937255, 0.803922)
	ItemButton.Image = Item.TextureId
	ItemButton.BorderSizePixel = 0
	ItemButton.Parent = ShopScrollingFrame
	ItemButton.Size = UDim2.new(0, 100,0, 104)



	ItemButton.MouseButton1Click:Connect(function()

		BuyingItemFrame.Visible = true
		BuyingItemFrame.ItemName.Text = Item.Name
		BuyingItemFrame.ItemImage.Image = Item.TextureId
		BuyingItemFrame.CostLabel.Text = "Cost: " ..  Item:WaitForChild("CostValue").Value
		BuyingItemFrame.QuantityLabel.Text = "Quantity:" ..  Item:WaitForChild("QuantityValue").Value
	end)
end


BuyItemButton.MouseButton1Click:Connect(function()

	if ItemDebounce == true then
		ItemDebounce = false
		local ItemPlayerGoingToBuyName = BuyingItemFrame:WaitForChild("ItemName").Text
		RemoteEvents.BuyingEvent:FireServer(ItemPlayerGoingToBuyName, BuyingItemFrame)
		task.wait(.5)
		ItemDebounce = true
	end
end)


RunService.RenderStepped:Connect(function()

	if Mouse.Target and Mouse.Target.Name == "Carrot" then



		if Mouse.Target:FindFirstChild("Grown") then

			if Mouse.Target:FindFirstChild("Grown").Value == true then

				SeedsFrame.Visible = true
				SeedsFrame:WaitForChild("GrownLabel").Text = "Fully Grown"

				local X = Mouse.X
				local Y = Mouse.Y
				SeedsFrame.Position = UDim2.new(0,X,0,Y)

			else

				local X = Mouse.X
				local Y = Mouse.Y
				SeedsFrame.Position = UDim2.new(0,X,0,Y)
				SeedsFrame.Visible = true
				SeedsFrame:WaitForChild("GrownLabel").Text = "Growing"
			end
		end
	elseif Mouse.Target and Mouse.Target.Name == "PineApple" then

		if Mouse.Target:FindFirstChild("Grown") then

			if Mouse.Target:FindFirstChild("Grown").Value == true then

				SeedsFrame.Visible = true
				SeedsFrame:WaitForChild("GrownLabel").Text = "Fully Grown"

				local X = Mouse.X
				local Y = Mouse.Y
				SeedsFrame.Position = UDim2.new(0,X,0,Y)

			else

				local X = Mouse.X
				local Y = Mouse.Y
				SeedsFrame.Position = UDim2.new(0,X,0,Y)
				SeedsFrame.Visible = true
				SeedsFrame:WaitForChild("GrownLabel").Text = "Growing"

			end
		end

	else
		SeedsFrame.Visible = false
	end
end)


This is the Server Script


local ServerStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Map = game.Workspace:WaitForChild("Map")
local Shops = Map:WaitForChild("Shops")
local BuyShop = Shops:WaitForChild("BuyShop")
local SellShop = Shops:WaitForChild("SellShop")
local PlotsFolder = Map:WaitForChild("Plots")




local RemoteEvents = ReplicatedStorage:WaitForChild("RemoteEvents")
local ShopItems = ServerStorage:WaitForChild("ShopItems")
local MaterialBlockFolder = ServerStorage:WaitForChild("Materials")
local MaterialSeedsFolder = ServerStorage:WaitForChild("Seeds")

local Effects = ServerStorage:WaitForChild("Effects")

local ShopDebounce =  false


for i,ShopBuyParts in pairs(BuyShop:WaitForChild("ShopPad"):GetChildren()) do


	ShopBuyParts.Touched:Connect(function(Hit)



		if ShopDebounce == false then
			ShopDebounce = true

			local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
			if Player then

				RemoteEvents.BuyingEvent:FireClient(Player)

			end
			task.wait(2)
			ShopDebounce = false
		end
	end)
end





function PlayerJoined(Player)


	local leaderstats = Instance.new("Folder")
	leaderstats.Parent = Player
	leaderstats.Name = "leaderstats"

	local Coins = Instance.new("IntValue")
	Coins.Parent = leaderstats
	Coins.Name = "Coins"
	Coins.Value = 500

	local PlayerOwns = Instance.new("BoolValue")
	PlayerOwns.Name = "PlayerOwns"
	PlayerOwns.Parent = Player
	PlayerOwns.Value = false


	task.wait(4)
	for i, Plot in pairs(PlotsFolder:GetChildren()) do
		if Plot:FindFirstChild("Owned").Value == false and PlayerOwns.Value == false then
			Player.Character:FindFirstChild("HumanoidRootPart").CFrame = Plot:WaitForChild("PlayerSpawn").CFrame
			Plot:WaitForChild("Owned").Value = true
			PlayerOwns.Value = true
			Plot:WaitForChild("PlayerOwns").Value = Player.Name

		end
	end			
end

function PlayerLeft(Player)

	for i, Plot in pairs(PlotsFolder:GetChildren()) do
		if Plot:FindFirstChild("PlayerOwns").Value == Player.Name then
			Plot:FindFirstChild("PlayerOwns").Value = ""
			Plot:FindFirstChild("Owned").Value = false
			Plot.Seeds:Destroy()
		end
	end
end


RemoteEvents.BuyingEvent.OnServerEvent:Connect(function(Player, ItemPlayerGoingToBuyName, BuyingItemFrame)

	if ItemPlayerGoingToBuyName then
		local Item = ShopItems:WaitForChild(ItemPlayerGoingToBuyName)
		local PlayerOwnsTool = Player.Backpack:FindFirstChild(Item.Name) or Player.Character:FindFirstChild(Item.Name)

		if PlayerOwnsTool then


			if Player.leaderstats.Coins.Value >= Item.CostValue.Value then

				BuyingItemFrame.BuyButton.Text = "Buying.."
				task.wait(.2)
				Player.leaderstats.Coins.Value -= Item.CostValue.Value
				PlayerOwnsTool.Handle.Quantity.Value += Item.QuantityValue.Value
				task.wait(.3)
				BuyingItemFrame.BuyButton.Text = "Buy"

			elseif Item.CostValue.Value >= Player.leaderstats.Coins.Value then

				BuyingItemFrame.BuyButton.BackgroundColor3 = Color3.new(1, 0.2, 0.2)
				task.wait(.5)
				BuyingItemFrame.BuyButton.Text = "Not Enough!"
				BuyingItemFrame.BuyButton.Text = "Buy"
				BuyingItemFrame.BuyButton.BackgroundColor3 = Color3.new(0.333333, 1, 0.498039)
			end
		end
		if Player.leaderstats.Coins.Value >= Item.CostValue.Value and PlayerOwnsTool == nil then
			BuyingItemFrame.BuyButton.Text = "Buying.."

			task.wait(.2)
			Player.leaderstats.Coins.Value -= Item.CostValue.Value
			local ItemClone = Item:Clone()
			ItemClone.Parent = Player.Backpack
			task.wait(.3)
			BuyingItemFrame.BuyButton.Text = "Buy"
		elseif Item.CostValue.Value >= Player.leaderstats.Coins.Value then
			BuyingItemFrame.BuyButton.Text = "Not Enough!"
			BuyingItemFrame.BuyButton.BackgroundColor3 = Color3.new(1, 0.2, 0.2)
			task.wait(.5)
			BuyingItemFrame.BuyButton.Text = "Buy"
			BuyingItemFrame.BuyButton.BackgroundColor3 = Color3.new(0.333333, 1, 0.498039)
		end
	end
end)


RemoteEvents.PlacingEvent.OnServerEvent:Connect(function(Player, Material, MaterialPosition, PlotSpaceEmptyValue)



	PlotSpaceEmptyValue.Value = false


	Material:FindFirstChild("Handle").Quantity.Value -= 1

	if MaterialBlockFolder:FindFirstChild(Material.Name) then

	elseif MaterialSeedsFolder:FindFirstChild(Material.Name) then


		for i,Plot in pairs(PlotsFolder:GetChildren()) do
			if Plot:FindFirstChild("PlayerOwns").Value ~= Player.Name then

			else

				local MaterialClone = MaterialSeedsFolder:FindFirstChild(Material.Name):Clone()
				MaterialClone.Grown.Value = false
				MaterialClone.CanCollide = false
				MaterialClone.Anchored = true
				MaterialClone.Position = MaterialPosition
				MaterialClone.PlayerPlanted.Value = Player.Name

				MaterialClone.PlotFlag.Value = PlotSpaceEmptyValue
				MaterialClone.Parent = Plot:FindFirstChild("Seeds")

				local PlacingEffect = Effects:WaitForChild("PlacingEffect"):Clone()

				PlacingEffect.Parent = MaterialClone
				task.wait(.4)
				PlacingEffect:Destroy()



			end
		end
	end
end)



game.Players.PlayerAdded:Connect(PlayerJoined)
game.Players.PlayerRemoving:Connect(PlayerLeft)
1 Like

Can you fix the coding embed? :joy:
Thanks, let me read

1 Like

Try:

RemoteEvents:WaitForChild("BuyingEvent").OnClientEvent:Connect(function()
1 Like

Still Sometimes doesn’t work
This is so weird
I feel RunService is doing that

1 Like

I mean, by commenting it does it work fine?