I have two scripts. A local one and a server one The server one is inside the ServerScriptService The client one is inside the StarterGui.
--server script. its not the entire script. player.Chatted:Connect(function(text) print(dummyCount) local chattext = string.lower(text) if chattext == "/createdummy" or chattext == "/cd" then if dummyCount < 4 then local clonedDummy = dummy:Clone() clonedDummy.Parent = folderPerPlayer clonedDummy.Name = player.Name.." Dummy "..dummyCount clonedDummy:MoveTo(humanoidRootPart.Position + Vector3.new(math.random(-10, 13), 7, math.random(-9, 12))) elseif dummyCount == 4 then print(player.Name) getWarning:FireClient(player, "(You can only see this!) You can't add anymore dummies! Use /removedummy (/rd) to delete all dummies!") --it wont fire end end
<><><><><><><><><><><><><><><><><>
--client script, full script. wont print message. local starterGui = game:GetService("StarterGui") local replicatedStorage = game:GetService("ReplicatedStorage") local getWarning = replicatedStorage:WaitForChild("getWarning") local function CreateSystemMessage(message, color, font, fontsize) starterGui:SetCore("ChatMakeSystemMessage",{ Text = message; Color = color; Font = font; FontSize = fontsize; }) end while true do CreateSystemMessage( "{System} Chat /createdummy (/cd) to spawn dummies and /removedummy (/rd) to remove dummies.", Color3.fromRGB(252, 165, 3), Enum.Font.FredokaOne, 56 ) wait(420) end getWarning.OnClientEvent:Connect(function(message) print(message) -- wont print? end) --[[ CreateSystemMessage( message, Color3.fromRGB(255, 115, 115), Enum.Font.FredokaOne, 56 ) ]]
your OnClientEvent
is never reached due to loop
There's the problem with only the client script, the server script is actually working fine and it's not the cause. Your client script is using loop which mean that the OnClientEvent
event will never listen because OnClientEvent
is never reached.
The solution is to separate the local script into 2 different local scripts so that loop is on 1st local script while OnClientEvent
is on 2nd local script.
==== SOLUTION ====
==== 1st LocalScript ====
local starterGui = game:GetService("StarterGui") local function CreateSystemMessage(message, color, font, fontsize) starterGui:SetCore("ChatMakeSystemMessage",{ Text = message; Color = color; Font = font; FontSize = fontsize; }) end while true do CreateSystemMessage( "{System} Chat /createdummy (/cd) to spawn dummies and /removedummy (/rd) to remove dummies.", Color3.fromRGB(252, 165, 3), Enum.Font.FredokaOne, 56 ) wait(420) end --[[ CreateSystemMessage( message, Color3.fromRGB(255, 115, 115), Enum.Font.FredokaOne, 56 ) ]]
==== 2nd LocalScript ====
local replicatedStorage = game:GetService("ReplicatedStorage") local getWarning = replicatedStorage:WaitForChild("getWarning") getWarning.OnClientEvent:Connect(function(message) print(message) -- now print because the event is reachable end)
In the future, you may want to make sure that the loop isn't stopping the event from listening because the loop typically stops other code lines outside the loop from being activated.
Happy Scripting!