Having problem with client if the game is multiplayer

Well, I’ve posted this about my game. It has a mechanic that, when you jump, changes the time (from day to night and vice versa). If you try it on your own, it works perfectly, only if it’s solo, I want to make it multiplayer but I’m having problems with it.

When the game is multiplayer, there are times that the time is changed without you jumping. I don’t have any ideas on how I can fix it.

Below here, it has a replica of how the mechanic works if you want to try to redo it and fix anything or other.
mainJumpScript.rbxl (53.7 KB)

But if you don’t want to do this, follow these steps:

Step by step of how I did the mechanic.
  1. Added parts inside a folder named “ObbyParts” named “Day” and “Night”. It can be only 1 of each to make the example.
  2. Add a LocalScript on StarterPlayerScripts
  3. Add this line of code:
local TweenService = game:GetService("TweenService")
local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local Lighting = game.Lighting

local ChangeTime = true

local player = Players.LocalPlayer
local PlayerGui = player:WaitForChild("PlayerGui")
task.wait(3)
local TouchGui = PlayerGui:FindFirstChild("TouchGui")

local function detectTime(parts)
	if not ChangeTime then
		for _, part in ipairs(parts) do
			if part.Name == "Day" then
				part.Transparency = 0
				part.CanCollide = true
			end
			if part.Name == "Night" then
				part.Transparency = 0.5
				part.CanCollide = false
			end
		end
	else
		for _, part in ipairs(parts) do
			if part.Name == "Day" then
				part.Transparency = 0.5
				part.CanCollide = false
			end
			if part.Name == "Night" then
				part.Transparency = 0
				part.CanCollide = true
			end
		end
	end
end

local debounce = false

UserInputService.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.Space then 
		if not debounce then
			debounce = true
		end
		if debounce then
			local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Linear)
			
			if Lighting.ClockTime == 12 then
				ChangeTime = true
				local targetTime = 0
				local tween = TweenService:Create(Lighting, tweenInfo, {ClockTime = targetTime})
				tween:Play()
				tween.Completed:Wait()
			else
				ChangeTime = false
				local targetTime = 12
				local tween = TweenService:Create(Lighting, tweenInfo, {ClockTime = targetTime})
				tween:Play()
				tween.Completed:Wait()
			end
		end
		debounce = false
	end
end)

if TouchGui ~= nil then
	local TouchControlFrame = TouchGui:WaitForChild("TouchControlFrame")
	local JumpButton = TouchControlFrame:WaitForChild("JumpButton")
	if JumpButton and JumpButton:IsA("ImageButton") then
		JumpButton.MouseButton1Click:Connect(function()
			if not debounce then
				debounce = true
			end
			if debounce then
				local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Linear)

				if Lighting.ClockTime == 12 then
					ChangeTime = true
					local targetTime = 0
					local tween = TweenService:Create(Lighting, tweenInfo, {ClockTime = targetTime})
					tween:Play()
					tween.Completed:Wait()
				else
					ChangeTime = false
					local targetTime = 12
					local tween = TweenService:Create(Lighting, tweenInfo, {ClockTime = targetTime})
					tween:Play()
					tween.Completed:Wait()
				end
			end
			debounce = false
		end)
	end
end

detectTime(workspace.ObbyParts:GetDescendants())

Lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
	detectTime(workspace.ObbyParts:GetDescendants())
end)
  1. And that’s all!
2 Likes

Change ‘ClockTime’ locally for a single client if you don’t want it to affect all clients.

Sorry for answering late. That makes sense, I’ll try another option for it, I’ll updating when I can.

Well, no success. I tried to add an IntValue named “ClockTime” and detect it when it changes the value, but it didn’t work. Sometimes it changes when any player dies or sometimes it changes when any player jumps, It’s weird, I’d say.

local TweenService = game:GetService("TweenService")
local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local Lighting = game.Lighting

local ChangeTime = true
local ClockTime = script.ClockTime

local player = Players.LocalPlayer
local PlayerGui = player:WaitForChild("PlayerGui")
task.wait(3)
local TouchGui = PlayerGui:FindFirstChild("TouchGui")

local function detectTime(parts)
	if not ChangeTime then
		for _, part in ipairs(parts) do
			if part.Name == "Day" then
				part.Transparency = 0
				part.CanCollide = true
			end
			if part.Name == "Night" then
				part.Transparency = 0.5
				part.CanCollide = false
			end
		end
	else
		for _, part in ipairs(parts) do
			if part.Name == "Day" then
				part.Transparency = 0.5
				part.CanCollide = false
			end
			if part.Name == "Night" then
				part.Transparency = 0
				part.CanCollide = true
			end
		end
	end
end

local debounce = false

UserInputService.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.Space then 
		if not debounce then
			debounce = true
		end
		if debounce then
			local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Linear)
			
			if Lighting.ClockTime == 12 then
				ChangeTime = true
				local targetTime = 0
				ClockTime.Value = targetTime
				local tween = TweenService:Create(Lighting, tweenInfo, {ClockTime = targetTime})
				tween:Play()
				tween.Completed:Wait()
			else
				ChangeTime = false
				local targetTime = 12
				ClockTime.Value = targetTime
				local tween = TweenService:Create(Lighting, tweenInfo, {ClockTime = targetTime})
				tween:Play()
				tween.Completed:Wait()
			end
		end
		debounce = false
	end
end)

if TouchGui ~= nil then
	local TouchControlFrame = TouchGui:WaitForChild("TouchControlFrame")
	local JumpButton = TouchControlFrame:WaitForChild("JumpButton")
	if JumpButton and JumpButton:IsA("ImageButton") then
		JumpButton.MouseButton1Click:Connect(function()
			if not debounce then
				debounce = true
			end
			if debounce then
				local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Linear)

				if Lighting.ClockTime == 12 then
					ChangeTime = true
					local targetTime = 0
					local tween = TweenService:Create(Lighting, tweenInfo, {ClockTime = targetTime})
					tween:Play()
					tween.Completed:Wait()
				else
					ChangeTime = false
					local targetTime = 12
					local tween = TweenService:Create(Lighting, tweenInfo, {ClockTime = targetTime})
					tween:Play()
					tween.Completed:Wait()
				end
			end
			debounce = false
		end)
	end
end

detectTime(workspace.ObbyParts:GetDescendants())

ClockTime:GetPropertyChangedSignal("Value"):Connect(function()
	detectTime(workspace.ObbyParts:GetDescendants())
end)

EDIT: this idea makes broke the mobile function, so it’s not a quite good idea.

1 Like