Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I change the skybox for only a specific client after touching a part to trigger it?

any idea why my local script is changing everybody's skybox instead of only the player who touches the part? this is a LocalScript in StarterCharacterScripts

local skybox = game:GetService("Lighting").Sky

game.Workspace.SkyboxTriggers.LotL.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        if player ~= nil then
        skybox.SkyboxUp = "rbxassetid://6115435142"
        skybox.SkyboxDn = "rbxassetid://6115431284"
        skybox.SkyboxBk = "rbxassetid://6115432902"
        skybox.SkyboxFt = "rbxassetid://6115433855"
        skybox.SkyboxLf = "rbxassetid://6115430469"
        skybox.SkyboxRt = "rbxassetid://6115432137"
        end    
    end
end)

When the player touches the Part called "LotL" the skybox changes as intended, but for every player. The server does not see this change.

1 answer

✓ Accepted answer

Use A Remote Event To Change The Sky Box For That Player.

Script 1:

	game.Workspace.SkyboxTriggers.LotL.Touched:Connect(function(hit)
	    if hit.Parent:FindFirstChild("Humanoid") then
	        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        if player ~= nil then
game.ReplicatedStorage:FindFirstChild("EventName"):FireClient(player)
	        end   
	    end
	end)

Local Script 2:

local skybox = game:GetService("Lighting").Sky

	  game.ReplicatedStorage:FindFirstChild("EventName").OnClientEvent:Connect(function()
	        skybox.SkyboxUp = "rbxassetid://6115435142"
	        skybox.SkyboxDn = "rbxassetid://6115431284"
	        skybox.SkyboxFt = "rbxassetid://6115433855"
        skybox.SkyboxLf = "rbxassetid://6115430469"
        skybox.SkyboxRt = "rbxassetid://6115432137"
	        end   
	    end
	end)

1 comment

0

Finally...thank you. I was stuck on this for an entire day. You're a lifesaver.

This discussion is preserved as it was. New answers, comments, and votes are closed.