I made a script which fires a RemoteEvent and change the Skybox on Touch. However, for some reason the Skybox does change if I test on Studio but as soon as I do a Local Server with 2 people it gets weird, for only one player it works and not for the other. I did try print debugging and it always tells me that the skybox did change but for player 2 it doesnt change it and doesnt print Fired. I tried to look in the devforums but I didn’t really find anything
(I couldn’t record Second Player cause of an OBS bug)
Here is the server side script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage.RemoteEvents:WaitForChild("ChangeTheSky")
local SecondEvent = ReplicatedStorage.RemoteEvents:WaitForChild("ReverseTheSky")
script.Parent.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
RemoteEvent:FireClient(player)
print("Fired")
end
end)
script.Parent.TouchEnded:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
SecondEvent:FireClient(player)
end
end)
Local Script:
local Lighting = game:GetService("Lighting")
local Skybox = Lighting.RealisticSky
local test = Skybox.SkyboxBk
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage.RemoteEvents:WaitForChild("ChangeTheSky")
local SecondEvent = ReplicatedStorage.RemoteEvents:WaitForChild("ReverseTheSky")
local ChangePartInChad = game.Workspace.map.Chad.sssssssss2s
local Id1ToChange = 12780346374
local function reverseSky()
Skybox.SkyboxBk = "http://www.roblox.com/asset/?id=150335574"
Skybox.SkyboxDn = "http://www.roblox.com/asset/?id=150335585"
Skybox.SkyboxFt = "http://www.roblox.com/asset/?id=150335628"
Skybox.SkyboxLf = "http://www.roblox.com/asset/?id=150335620"
Skybox.SkyboxRt = "http://www.roblox.com/asset/?id=150335610"
Skybox.SkyboxUp = "http://www.roblox.com/asset/?id=150335642"
end
local function ChadSky()
Skybox.SkyboxBk = "http://www.roblox.com/asset/?id="..Id1ToChange
Skybox.SkyboxDn = "http://www.roblox.com/asset/?id="..Id1ToChange
Skybox.SkyboxFt = "http://www.roblox.com/asset/?id="..Id1ToChange
Skybox.SkyboxLf = "http://www.roblox.com/asset/?id="..Id1ToChange
Skybox.SkyboxRt = "http://www.roblox.com/asset/?id="..Id1ToChange
Skybox.SkyboxUp = "http://www.roblox.com/asset/?id="..Id1ToChange
end
RemoteEvent.OnClientEvent:Connect(ChadSky)
RemoteEvent.OnClientEvent:Connect(function()
print("Chad Sky Box Changed")
end)
SecondEvent.OnClientEvent:Connect(reverseSky)
What is the purpose of this function? From this code, it looks like that when the player touch ends the sky reverts to normal which might be causing your issue.
I added the function to change the skybox again (in the local Script) and ,because I, personally then don’t really know what I could do then. TouchEnded seemed like the only option to me. If there is another way, please tell me what I could use.
Why use a LocalScript to change the skybox? That part should be handled on the server.
The skybox is loaded onto the clients computer so that’s why different players see different skyboxes.
I tried it on a script before but if someone touches it everyone can see the skybox change. I only want the skybox to change in that area so I tried with a Local Script with the help of a script
If the Local Script is located in StarterCharacterScripts then this version should work:
-- SERVER --
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage.RemoteEvents:WaitForChild("ChangeTheSky")
local SecondEvent = ReplicatedStorage.RemoteEvents:WaitForChild("ReverseTheSky")
script.Parent.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
RemoteEvent:FireClient(player)
print("Fired")
end
end)
-- LOCAL SCRIPT --
local Lighting = game:GetService("Lighting")
local Skybox = Lighting.RealisticSky
local test = Skybox.SkyboxBk
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage.RemoteEvents:WaitForChild("ChangeTheSky")
local SecondEvent = ReplicatedStorage.RemoteEvents:WaitForChild("ReverseTheSky")
local ChangePartInChad = game.Workspace.map.Chad.sssssssss2s
local Id1ToChange = 12780346374
local function reverseSky()
Skybox.SkyboxBk = "http://www.roblox.com/asset/?id=150335574"
Skybox.SkyboxDn = "http://www.roblox.com/asset/?id=150335585"
Skybox.SkyboxFt = "http://www.roblox.com/asset/?id=150335628"
Skybox.SkyboxLf = "http://www.roblox.com/asset/?id=150335620"
Skybox.SkyboxRt = "http://www.roblox.com/asset/?id=150335610"
Skybox.SkyboxUp = "http://www.roblox.com/asset/?id=150335642"
end
local function ChadSky()
Skybox.SkyboxBk = "http://www.roblox.com/asset/?id="..Id1ToChange
Skybox.SkyboxDn = "http://www.roblox.com/asset/?id="..Id1ToChange
Skybox.SkyboxFt = "http://www.roblox.com/asset/?id="..Id1ToChange
Skybox.SkyboxLf = "http://www.roblox.com/asset/?id="..Id1ToChange
Skybox.SkyboxRt = "http://www.roblox.com/asset/?id="..Id1ToChange
Skybox.SkyboxUp = "http://www.roblox.com/asset/?id="..Id1ToChange
end
RemoteEvent.OnClientEvent:Connect(ChadSky)
RemoteEvent.OnClientEvent:Connect(function()
print("Chad Sky Box Changed")
end)
reverseSky()
After some thinking, I believe it isn’t working because the teleport script is separate from the sky box script so it is teleporting the player before it can register the touch in the sky box script.
To fix this you should combine both the teleport script and the server sky box script into one script.