SetCore() messages not replicating properly to the server

I’ve been working on a JTOH-esque game with some friends as a passion project, and currently, I have hit a roadblock with the message system, and I haven’t been able to figure it out. The script is supposed to display a server message telling that a player has completed a tower (obstacle course) with a time, and tower name. It replicates correctly on the client, and will not display a message if the player touches a winpad not associated with the tower they are currently doing.

However, this is not replicating properly to the server, and I have not figured a workaround for it. The total time is not being replicated properly, and if the player touches the incorrect winpad, a message will still show up to the server. I know it has to do something with the fact that it is a localscript, but scripting is definitely not my strong suit, so that is why I am asking to help:

  • Properly replicate the time on the server
  • Properly replicate false wins on the server
  • Some sort of method to grab a player’s local value from a server script

MessageScript (displays server messages)

local ReplicatedStorage = game:GetService('ReplicatedStorage')
local StarterGUI = game:GetService('StarterGui')
local timeresult = game.StarterGui.TimerGUI.Frame.Timer
local remoteEvent = ReplicatedStorage:WaitForChild('WinpadEvent')
local debounce = false
local Player = game.Players.LocalPlayer
local teams = game:GetService("Teams")

-- textColor = BrickColor.new('Lime green')

local function win(playerName, towerName, difficulty, towercertifcation)
	if debounce == false then
	debounce = true	
	local towertime = Player.PlayerGui.TimerGUI.Frame.Timer.Text
	local towervalue = Player.CurrentTower.Value
	print(towertime)
	if towervalue == towercertifcation then
	game.StarterGui:SetCore('ChatMakeSystemMessage', {
		Text = '[SERVER]: '..playerName..' has beaten '..towerName.. ' in ' .. towertime..'!';
		Font = Enum.Font.SourceSansBold;
		Color = difficulty;
		FontSize = Enum.FontSize.Size24;
		})
		wait(1)
		debounce = false
		elseif playerName ~= game.Players.LocalPlayer.Name then
		game.StarterGui:SetCore('ChatMakeSystemMessage', {
			Text = '[SERVER]: '..playerName..' has beaten '..towerName.. ' in ' .. towertime..'!';
			Font = Enum.Font.SourceSansBold;
			Color = difficulty;
			FontSize = Enum.FontSize.Size24;
			})
		wait(1)
		debounce = false
		else
		wait(1)
		debounce = false
		end
	end
end

remoteEvent.OnClientEvent:Connect(win)

WinScript (found in each winpad, sends an event to the messagescript)

local telepoint = Vector3.new(-91.934, 164.76, -346.019) 
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local remoteEvent = ReplicatedStorage:WaitForChild('WinpadEvent')
local TowerName = script.Parent.Parent
local Difficulty = script.Parent:WaitForChild("Difficulty")
local teams = game:GetService("Teams")
local Cert = script.Parent:WaitForChild('TowerCertification')

local function onPartTouch(otherPart)
	local debounce = false
	local partParent = otherPart.Parent
	local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
	local player = game.Players:GetPlayerFromCharacter(otherPart.Parent)
	if humanoid then
		if debounce == false then
		debounce = true
		humanoid.Parent.Torso.CFrame = CFrame.new(telepoint + Vector3.new(0,3,0))
		player.Team = teams.Winners
		remoteEvent:FireAllClients(humanoid.DisplayName, TowerName.Name, Difficulty.Value, Cert.Value)
		end
	end
end
script.Parent.Touched:Connect(onPartTouch)

image
image

1 Like

To help us to help you could you put some more prints in.
I usually use the format for these ‘debug’ prints as in print(“NameOfVariableOrFunctionOrLocationInScript=”,valueOfVariable[if appropriate])
Pleas do that and ley us see the modified script and output.

This will be different for each player.

I’m aware that’s part of the issue, though I do not know how to replicate a value in a client’s GUI to SetCore, which is partially why I made this post in the first place. The rest of the values that SetCore gets are from values in the server or the humanoid touching the winpad. Normally, I’d do this in the server, but I could not get the server to properly get the time from the client, as that would show up as nil, as I can only assume something like that can only be done on a local script.

I don’t really see what prints need to be added beyond printing the output of the values gotten from the remoteevent, as well as timetimer, which prints already.

All other values are replicating though, so that must be the error.

Because the rest of the values are replicated from the server, while TimerGUI comes from the client, since I was not able to find a workaround of obtaining the local gui value from the server.

remoteEvent:FireAllClients(humanoid.DisplayName, TowerName.Name, Difficulty.Value, Cert.Value)

You can use a remote function sent to the client and then retrieve the returned value.
Read more: Bindable Events and Functions | Roblox Creator Documentation

I ended up just recoding a lot of the core scripting, which fixed the issues with information not being replicated properly, as well as fixing some other secondary issues, but I did use a remote function after reading up on it. Thanks!

2 Likes