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

Script is running for all players, not only the player who clicked it?

SERVERSCRIPT

I made a GUI button if you click it it parents a sky to lighting and puts the other in ServerStorage. This all works perfect but the only problem is I thought it shows only for the player who clicked the button but it shows for everyone. I tried using a LocalScript but It doesn't work when I try reference things outside of StarterGUI with a LocalScript it just doesn't run but when I used a ServerScript, it worked but it happens for all players too.

local changeTime = true
local button = script.Parent
local day = game.Lighting.SunsetSereneSky

local night = game.ServerStorage.NightSky

button.MouseButton1Up:Connect(function()
	if changeTime == true then
		
		button.Text = "Time: Night"
		day.Parent = game.ServerStorage
		
		night.Parent = game.Lighting
		changeTime = false
	elseif changeTime == false then
		button.Text = "Time: Day"
		night.Parent = game.ServerStorage
		
		day.Parent = game.Lighting
		changeTime = true
		
	end
end)

this is my problem plz fix it ty

2 answers

✓ Accepted answer

Debugging

When you ran the local script, was there an error? What works and what didn't work?

Server vs Local Scripts

Server Scripts are powerful, they have access to almost everything (except of course the client). What about Local Scripts? Well, they are restricted access to objects inside game.ServerStorage and game.ServerScriptService. You can confirm this by looking at the explorer when you test the game.

Now, Server Scripts make applications to ALL of the player's screens. Local Scripts, when using Filtering Enabled of course, will make applications LOCALLY (with exceptions of animations and physics). This means if we want changes to appear on their screen only, we need to use a Local Script.

My Assumption

I think your local script errors when looking for game.ServerStorage.NightSky. You want to store the NightSky object to somewhere where the local script can access it. I personally recommend ReplicatedStorage.

2 comments

0

big brain formatting here

0

now that is what i've been missing... I forgot about my question lol and i kept it here for a week + and i forgot to see it if someone answered, but i see a big big mind talk here thanks.

Ok, you have to use a local script, you said you used one but the problem is, you referenced serverstorage, objects inside serverstorage and serverscript service only appear in the server, if you check your explorer while on a client, you will notice serverscript service and serverstorage are empty even if you put something inside them before running the game. But they are not empty on the server, so just store it in replicated storage instead like this:

--Local Script
local changeTime = true
local button = script.Parent
local day = game.Lighting.SunsetSereneSky

local night = game.ReplicatedStorage.NightSky

button.MouseButton1Up:Connect(function()
    if changeTime == true then

        button.Text = "Time: Night"
        day.Parent = game.ReplicatedStorage

        night.Parent = game.Lighting
        changeTime = false
    elseif changeTime == false then
        button.Text = "Time: Day"
        night.Parent = game.ReplicatedStorage

        day.Parent = game.Lighting
        changeTime = true

    end
end)

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