Why is my remoteEvent not firing..?

Local Script Function is fully working, the remoteEvent is not firing and i’m unsure as to why… there’s no errors that appear; any ideas…?

Script

local ToolEvents = {}


local function toolAdded(val)
	local Event = val:WaitForChild("Events",30):WaitForChild("ToolEvent",30) and val.Events.ToolEvent or nil
	local handle = val:WaitForChild("Handle",30) and val.Handle or nil

	if not handle:IsA("MeshPart") then
		return false
	end

	if not Event and not val:FindFirstChild("Events") then
		local newFolder = Instance.new("Folder")
		newFolder.Name = "Events"
		newFolder.Parent = val
	end

	if not Event and not val.Events:FindFirstChild("ToolEvent") then
		local newEvent = Instance.new("RemoteEvent")
		newEvent.Name = "ToolEvent"
		newEvent.Parent = val.Events
		Event = newEvent
	end

	ToolEvents[val] = Event.OnServerEvent:Connect(function(plr,type,arg1,arg2,arg3,arg4,arg5)
		warn({plr.Name,type})
		if string.lower(type) == "clean skin" then
			local tool = plr.Backpack:FindFirstChild("Clean") or plr.Backpack:FindFirstChild("Wrestling Tool") or game.Workspace[plr.Name]:FindFirstChild("Clean") or game.Workspace[plr.Name]:FindFirstChild("Wrestling Tool") or nil
			local handle = tool:FindFirstChild("Handle")
			local newId = string.split(arg1,"http://www.roblox.com/asset/?id=")[2] or string.split(arg1,"rbxassetid://")[2] or arg1			
			handle.TextureID = "rbxassetid://"..newId
			return "clean skin updated"
		end

		return "went through all"
	end)
	
end

for ind,val in game:GetDescendants() do
	if not val:IsA("Tool") or val.Name ~= "Clean" and val.Name ~= "Wrestling Tool" then
		continue
	end
	
	toolAdded(val)
end

game.DescendantAdded:Connect(function(Item)
	if not Item:IsA("Tool") or Item.Name ~= "Clean" and Item.Name ~= "Wrestling Tool" then
		return
	end
	toolAdded(Item)
end)

Local Script

--/Variables\--
local Tool = script.Parent
--[[Table Functions]]
local ButtonFunctions = {}

--/Functions\--
local BindedFunctions = {
	["Handle Skin Swapper"] = {
		Description = "";
		Function = function(id)
			local Event = script.Parent:WaitForChild("Events",30):WaitForChild("ToolEvent",30) and script.Parent.Events.ToolEvent or nil
			Event:FireServer("clean skin",id)
		end,
	}
}

local Skins = require(game.StarterPack["Wrestling Tool"].ModuleScript)

for Name,Table in Skins do
	local nButton = script.TextButton:Clone()
	nButton.Text = tostring(Name)
	nButton.Parent = game.Players.LocalPlayer.PlayerGui:FindFirstChild("Clean_Selection").CanvasGroup.ScrollingFrame
	ButtonFunctions[nButton] = nButton.MouseButton1Down:Connect(function()
		BindedFunctions["Handle Skin Swapper"].Function(Table.ID)
	end)
end

There are quite a few if statements, so I would add some prints to see if something is returning false when it should be true.

Also type is a keyword so it might be causing a problem if you are using it as a parameter.

local Event = script.Parent:WaitForChild("Events",30):WaitForChild("ToolEvent",30) and script.Parent.Events.ToolEvent or nil

This could also be an issue, as if the child “Events” has already loaded, the waitForChild event won’t fire, it’ll just wait until the timeout, and if it doesn’t error the logic here would probably return nil. (Can’t test it myself right now).

I did not know that at all, that’s very useful to know. Thank you so much! It fully works now after your suggestion!

1 Like

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