I am currently making a stopwatch system that starts when a part is touched, and ends when another part is touched. When the EndPart
is touched, a RemoteEvent fires to the server to send a system message through the chat. However, the issue with this is that the parameter used to fire the RemoteEvent is returning my Player.Name
intead of the appropriate value (which would be MainUI.Text
).
Local script code:
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Humanoid = Character:FindFirstChild("Humanoid")
local RemoteEvent = game.ReplicatedStorage:FindFirstChild("toSysMessage")
local PlayerUI = Player.PlayerGui
local ScreenGUI = PlayerUI:WaitForChild("Stopwatch")
local MainUI = ScreenGUI:FindFirstChild("MainUI")
local StartPart = game.Workspace:FindFirstChild("StartPart")
local EndPart = game.Workspace:FindFirstChild("EndPart")
local Started = false
local function IsHuman(instance)
if instance.Parent:FindFirstChild("Humanoid") then
return true
end
return false
end
local function StartPartTouched(hit)
if IsHuman(hit) and not Started then
Started = true
repeat MainUI.Text = MainUI.Text + 0.1 wait(0.1) until not Started
end
end
local function EndPartTouched(hit)
if IsHuman(hit) and Started then
Started = false
MainUI.TextColor3 = Color3.fromRGB(255, 170, 0)
RemoteEvent:FireServer(MainUI.Text) -- REMOTE EVENT BEING FIRED
end
end
local function HumanoidDied()
if Started then
Started = false
MainUI.Text = 0.0
end
end
StartPart.Touched:Connect(StartPartTouched)
EndPart.Touched:Connect(EndPartTouched)
Humanoid.Died:Connect(HumanoidDied)
Server script code:
local RemoteEvent = game.ReplicatedStorage:FindFirstChild("toSysMessage")
RemoteEvent.OnServerEvent:Connect(function(Time)
print(Time)
end)
Reproduction Steps: