Hey there all!
So, I was scripting a gamemode (Deathmatch) and it seemed like it didn’t work. I’ve got a Server Script and a Module Script. Here are the pictures of the explorer and the code:
Pics
Code
Gamemode Module
--// Module Variables
local Deathmatch = {
MatchOverBE = Instance.new("BindableEvent");
}
--// Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
--// ReplicatedStorage Variables
local Values = ReplicatedStorage:WaitForChild("Values")
local Status = Values:WaitForChild("Status")
local CurrentGamemode = Values:WaitForChild("CurrentGamemode")
local Modules = ReplicatedStorage:WaitForChild("Modules")
local _Ranking = require(Modules:WaitForChild("_Ranking"))
local _Player = require(Modules:WaitForChild("_Player"))
local PlayerContainer = ReplicatedStorage:WaitForChild("PlayerContainer")
--// Main
function Deathmatch:Start()
CurrentGamemode.Value = "Deathmatch"
--[[ Commented because this part won't print anything.
for _, IsPl in ipairs(PlayerContainer:GetChildren()) do
if Players:FindFirstChild(IsPl.Name) then
local FoundPlayer = Players:FindFirstChild(IsPl.Name)
print(FoundPlayer.Name)
print(FoundPlayer:GetFullName())
end
end
]]
task.wait(15)
self["MatchOverBE"]:Fire()
end
return Deathmatch
Server
local Modules = ReplicatedStorage:WaitForChild("Modules")
local Deathmatch = require(Gamemodes:WaitForChild("Deathmatch"))
Deathmatch:Start()
Deathmatch.MatchOverBE.Event:Connect(function()
print("Ended!")
end)
It does not print or do anything at all except for the value changing. Thanks for any help!
1 Like
Could you please share the code that generates the ‘PlayerContainer’ folder?
Whoops, accidentally blocked it out in the picture. It’s actually a (blank) folder inside of ReplicatedStorage.
A string value named as the player’s name gets added in that folder when you click “Deploy”. (Don’t worry about the Deploy and StringValue adding part, it works fine there.)
No problem!
Could you please share the code that creates the StringValue with the player’s name?
1 Like
LocalScript
DeployButton.MouseButton1Click:Connect(function()
MenuGui.Enabled = false
InGameGUI.Enabled = true
camera.CameraType = Enum.CameraType.Custom
IsActiveRE:FireServer(true, "InRound")
HumanoidRootPart.CFrame = game.Workspace.Nature.Spawns:GetChildren()[math.random(1, #game.Workspace.Nature.Spawns:GetChildren())].CFrame
end)
Server Script
IsActiveRE.OnServerEvent:Connect(function(player, bool, value)
if bool then
local val = Instance.new("StringValue")
val.Name = player.Name
val.Value = value
val.Parent = PlayerContainer
else
local isFound = PlayerContainer:FindFirstChild(player.Name)
if isFound then
isFound:Destroy()
else
warn("Couldn't find StringValue for " .. player.Name)
end
end
end)
Interesting. Couple of points:
- Your .OnServerEvent handler expects 3 parameters, but only 2 are fulfilled, those being
player
and bool
. No value
is passed to the server.
- If you are expected a StringValue to be made that holds the player’s name, you would have to FireServer with true as the argument, along with a value, so the LocalScript would look something like this:
DeployButton.MouseButton1Click:Connect(function()
IsActiveRE:FireServer(true, "") -- true: creates StringValue with player's name | "": sets the StringValue's value to "".
end)
Whoops, yeah I accidentally sent the wrong part of the code, where it sends you back to menu. (lol😂)
Edited the code it now explains a lot lot more.
Now, we will begin the debug process!
For the script that handles OnServerEvent: is it the ModuleScript or is it it’s own script/part of the script shown in the original question?
The .OnServerEvent
is inside of another script inside of ServerScriptService
named RemoteEvents
which is only for RemoteEvents.
Try to add a print statement to the script to make sure it’s firing:
IsActiveRE.OnServerEvent:Connect(function(player, bool, value)
print("Fired! Arguments: bool:", bool, "| value:", value);
if bool then
print("Bool is true. Creating...");
local val = Instance.new("StringValue")
val.Name = player.Name
val.Value = value
val.Parent = PlayerContainer
else
print("Bool is false! Finding...");
local isFound = PlayerContainer:FindFirstChild(player.Name)
if isFound then
isFound:Destroy()
else
warn("Couldn't find StringValue for " .. player.Name)
end
end
end)
And let me know what it prints.
I think you got confused. This part is already working. The module was only changing the value of CurrentGamemode
but it didn’t perform the other stuff.
The module is changing the value of CurrentGamemode
, but it didn’t print anything in your commented code because it found nothing in the PlayerContainer
. Tracing this back to it’s root (the script that is in charge of creating the values that goes into PlayerContainer
) lets us figure out why the module isn’t finding what it’s supposed to be finding.
I never had any line which prints out something inside the PlayerContainer
…
Is this not where the problem is? Or am I mistaken? My apologies if I am mistaken.
1 Like
No problem!
You’re mistaking in 1 part, check that line
This part won’t print anything at all, that’s why I commented it.