Hi
I'm making a very simple race against the clock game. The player has to run a very simple course, and they see their time updated every second. There is a part on the finish line which, when they touch, can tell them their finish time. Each second I'd like to send the time from the server to the client. I will then post this updated time in a screengui on the client side.
I have a server script which fires to the client when the player is added, and I would like it to fire a start time to the client. The bit I am struggling with is how to refer to the start time variable on the client side. The server code is held in "ServerScriptService" and the client code is held in "StarterGui".
In the client side I am getting a warning when I refer to the server side "starttime" variable, and I am getting an error which says "Argument 1 - missing ot nil"
Thank you once again for your help.
Chris
--- Server side script---
local Players = game:GetService("Players") local welcomePlayerEvent = Instance.new("RemoteEvent") welcomePlayerEvent.Parent = game.ReplicatedStorage welcomePlayerEvent.Name = "WelcomePlayerEvent" local starttime=0 -- this is the start time variable local function onPlayerAdded(player) -- This is where I think I am sending the starttime to the client welcomePlayerEvent:FireClient(player,starttime) end Players.PlayerAdded:Connect(onPlayerAdded)
--- Client Side Script
local Players = game:GetService("Players") local ReplicatedStorage = game:GetService("ReplicatedStorage") local player = Players.LocalPlayer local welcomePlayerEvent = ReplicatedStorage:WaitForChild("WelcomePlayerEvent") local playerGui = player:WaitForChild("PlayerGui") -- *** this line is where I am getting a warning "Unknown Global starttime" local time = ReplicatedStorage:WaitForChild(starttime) -- Create a screengui which posts a welcome message to a player local welcomeScreen = Instance.new("ScreenGui") welcomeScreen.Parent = playerGui local welcomeMessage = Instance.new("TextLabel") welcomeMessage.Size = UDim2.new(0, 200, 0, 50) welcomeMessage.Parent = welcomeScreen welcomeMessage.Visible = false welcomeMessage.Text = "Welcome to the game!"..player.name local function onWelcomePlayerFired() welcomeMessage.Visible = true for i=1,10,1 do wait(1) end welcomeMessage.Visible = false end welcomePlayerEvent.OnClientEvent:Connect(onWelcomePlayerFired)