#how do i change the sky depending on the player's y level

105 messages · Page 1 of 1 (latest)

tame tide
#

for example, i want to change the sky for the player when they reach 40 studs into the air. I have a night sky in replicatedstorage. I don't know how to do it.

#

i'll post the code I have written for it so far

#

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SkyChangeEvent = Instance.new("RemoteEvent")
SkyChangeEvent.Name = "SkyChangeRequest"
SkyChangeEvent.Parent = ReplicatedStorage

function onChangeSkyRequest(player)
    local sky = ReplicatedStorage:WaitForChild("NightSky")
    game.Lighting.Sky = sky
end

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        local humanoid = character:WaitForChild("Humanoid")
        local rootPart = character:WaitForChild("HumanoidRootPart")

        local function onMove()
            if humanoid.MoveDirection.Magnitude > 0 and rootPart then
                local yLevel = rootPart.Position.Y
                if yLevel >= 40 then
                    SkyChangeEvent:FireClient(player)
                end
            end
        end

        humanoid:GetPropertyChangedSignal("Move"):Connect(onMove)
    end)
end)
#

there

#

someone help plz

covert quartz
#

Yes

#

Do you want the sky to be changed for everyone or just the player ?

#

Like do you want only the players see his sky level

tame tide
#

just the player

#

sorry for responding quite later i was playing tetris

#

@covert quartz

lean prairie
gaunt crestBOT
#

studio** You are now Level 3! **studio

lean prairie
#

How you could do it instead is use the Position property of the root part

tame tide
lean prairie
#

Also I couldn't help to notice, are you using a server script for this?

tame tide
#

this script is located in uhhh let me check

lean prairie
tame tide
#

startercharacterscripts

#

it's a localscript

lean prairie
#

How are you firing to client then

tame tide
#

i'll show you another script that hopefully solves your question

tame tide
lean prairie
#

Yeah, I knew it was off

tame tide
#

this script:


local ReplicatedStorage = game:GetService("ReplicatedStorage")
local player = game.Players.LocalPlayer
local SkyChangeEvent = ReplicatedStorage:WaitForChild("SkyChangeRequest")

SkyChangeEvent.OnClientEvent:Connect(function()
    print("Changing sky...")
    -- You can add any client-side effects here
end)

is in startercharacterscripts and is a localscript

lean prairie
#

Why don't you just do it directly in the script that receives the signal?

tame tide
#

you can do that?

lean prairie
#

Yes..

#

I mean does the player not see their character?

tame tide
#

lol ok i'm quite new to scripting and i used ai for some bits of the script

tame tide
lean prairie
#

Yeah so they must know where it is

#

They even calculate the physics for their character that then replicate

#

-which is why exploiters can teleport

tame tide
#

fair enough

#

i'm not sure how i'm supposed to put that script directly into the script in serverscript service, do i just add a localscript onto the normal script in serverscript service and paste the code?

#

like this

lean prairie
#

Local scripts can only run on the client, so no, not in server script service

tame tide
#

oh ok

#

that makes sense

lean prairie
#

You would wanna put it into the StarterCharacterScripts

tame tide
#

yeah that's what i've done

#

but you said something about combining the two scripts into one right

lean prairie
#

Yeah, good, then you just need to change it to use position and optionally move the server script into the local script

tame tide
#

hmm

#

let me think

lean prairie
tame tide
#

lemme try

lean prairie
#

I don't see anything server specific other then the remote

#

You replace the remote firing with a function to change the skybox

tame tide
#

i have the nightsky in replicatedstorage before it gets changed is that what i'm supposed to do

lean prairie
tame tide
#

when i ran the project before it said this:

lean prairie
#

Okay so, you replace 20 with the function on 6

tame tide
#

i haven't ran it again

#

okay lemme do that

#

like this?

lean prairie
#

No.

#

Just call it like a normal function, the remote is obselete

tame tide
#

idk how to do that sorry i told you i'm new to luau

lean prairie
#

onChangeSkyRequest()

tame tide
#

okay

lean prairie
#

Also remove the player argument from the function, it's not being used.

tame tide
#

okay

#

wait but i want to check if the player's y level is above 40 and if it is i want to change the sky don't i need the player argument for that

gaunt crestBOT
#

studio** You are now Level 9! **studio

lean prairie
#

You already know the player at all times

tame tide
lean prairie
#

It'd be a lot easier if I could just live edit w/ you

tame tide
#

i can add you as a collaborator if you want

lean prairie
#

Okay here's the breakdown of what I'm trying to do

lean prairie
#

That's gonna be way easier

tame tide
#

lol it looked like you were typing a whole essay

#

what's your roblox username

lean prairie
lean prairie
tame tide
#

ah ok

lean prairie
#

But I gave up halfway

tame tide
#

lol

#

ok lemme save the place to roblox first

#

i'll let you know when you have been added as a collaborator

lean prairie
#

Don't you need to friend someone to grant them edit permission?

tame tide
#

idk let me check

#

i'm still tryna save it to roblox lol

lean prairie
#

Control + S should save it

#

It'll tell you at the bottom

tame tide
#

i sent you a friend request

#

my roblox username is ThelongestusrnameEvr

lean prairie
#

Yeah I noticed, I don't get that many friend requests for yours to be lost

tame tide
#

lol

#

ok you should be able to edit now

covert quartz
#

And then you can change the color

tame tide
#

hey it's alright i've got someone helping me right now thanks for your help

covert quartz
#

Alr sorry

lean prairie
#

Alright all solved

gaunt crestBOT
#

studio** You are now Level 4! **studio