#how do i change the sky depending on the player's y level
105 messages · Page 1 of 1 (latest)
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
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
just the player
sorry for responding quite later i was playing tetris
@covert quartz
I think the Move property isn't actually where the player is, rather, where it's trying to go. I don't know though
** You are now Level 3! **
How you could do it instead is use the Position property of the root part
oh ok do you know what thing i should use then
oh just saw this lol
Also I couldn't help to notice, are you using a server script for this?
this script is located in uhhh let me check
How are you firing to client then
i'll show you another script that hopefully solves your question
wait sorry i mean serverscript service and it's just a normal script
Yeah, I knew it was off
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
Why don't you just do it directly in the script that receives the signal?
you can do that?
lol ok i'm quite new to scripting and i used ai for some bits of the script
and yes they do see their character
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
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
Local scripts can only run on the client, so no, not in server script service
You would wanna put it into the StarterCharacterScripts
yeah that's what i've done
but you said something about combining the two scripts into one right
Yeah, good, then you just need to change it to use position and optionally move the server script into the local script
You can just copy paste this into the local script I think
yeah ok
lemme try
I don't see anything server specific other then the remote
You replace the remote firing with a function to change the skybox
i have the nightsky in replicatedstorage before it gets changed is that what i'm supposed to do
Well first, how does the local script look now
when i ran the project before it said this:
Okay so, you replace 20 with the function on 6
idk how to do that sorry i told you i'm new to luau
onChangeSkyRequest()
Also remove the player argument from the function, it's not being used.
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
** You are now Level 9! **
shh
We are the client.
You already know the player at all times
okay so do I get rid of this, sorry if i'm very hard to work with
No that's fine
It'd be a lot easier if I could just live edit w/ you
i can add you as a collaborator if you want
Okay here's the breakdown of what I'm trying to do
Or just do this yeah
That's gonna be way easier
I was
ah ok
But I gave up halfway
lol
ok lemme save the place to roblox first
i'll let you know when you have been added as a collaborator
Don't you need to friend someone to grant them edit permission?
Yeah I noticed, I don't get that many friend requests for yours to be lost
Local Script -> Lighting.Sky...
And then you can change the color
hey it's alright i've got someone helping me right now thanks for your help
Alr sorry
Alright all solved
** You are now Level 4! **