I’ve been trying to make two parts, that react on players touch. Touching the part toggles some ligting features. Basicaly, I want to make script where if players are underground, there is dark ligting and on surface is regular light (there’s only one entrance / exit).
I’m using LocalSript within the parts in the workspace, but it does not seem to be working.
Scripts:
local Lighting = game.Lighting
script.Parent.Touched:Connect(function(LightUp)
if LightUp.Parent:FindFirstChild("Humanoid") then
Lighting.FogEnd = 1300
Lighting.FogEnd = 1000000000
Lighting.FogStart = 0
Lighting.Brightness = 4
Lighting.ClockTime = 14
Lighting.OutdoorAmbient = Color3.fromRGB(120, 120, 120)
end
end)
local Lighting = game.Lighting
script.Parent.Touched:Connect(function(LightDown)
if LightDown.Parent:FindFirstChild("Humanoid") then
Lighting.FogEnd = 1300
Lighting.FogStart = 10
Lighting.Brightness = 0
Lighting.OutdoorAmbient = Color3.fromRGB(0, 0, 0)
Lighting.ClockTime = 24
end
end)
Thanks for help in advance.
1 Like
I saw that you typed “Conect” instead of “Connect”.
That’s because I was not copying, but rewriting the script. Everything in the actual script is spelled correctly.
The issue here is that you’re using LocalScripts. Use a script instead.
As stated by the API Reference, a LocalScript will only run Lua code if it is a descendant of one of the following objects:
- A Player’s
Backpack
, such as a child of a Tool
- A Player’s
character
model
- A Player’s
PlayerGui
- A Player’s
PlayerScripts
.
- The
ReplicatedFirst
service
However, using regular script changes the ligting for all players, and that’s not what I want. I want to change the enviroment only for one certain player.
Then you may want to use remote events, I believe. You can fire a remote event to the client and change the lighting there. When passing your argument in your remote event, you can pass the player which you can get using GetPlayerFromCharacter.
local player = game.Players:GetPlayerFromCharacter(LightUp.Parent)
game.ReplicatedStorage.Your_Remote:FireClient(player)
And on local script receive the remote:
game.ReplicatedStorage.Your_Remote.OnClientEvent:Connect(function(player)
-- Set your lighting properties
That still doesn’t help me much, because I never worked with remote events and I have no idea how to send signal to certain client.
Well okay, but where should I place the localscript?
I put the script into the part
script.Parent.Touched:Connect(function(LightUp)
if LightUp.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(LightUp.Parent)
game.ReplicatedStorage.LightUp:FireClient(player)
end
end)
And I don’t know, where to put the local script
local Lighting = game.Lighting
game.ReplicatedStorage.LightUp.OnClientEvent:Connect(function(player)
Lighting.FogEnd = 1300
Lighting.FogEnd = 1000000000
Lighting.FogStart = 0
Lighting.Brightness = 4
Lighting.ClockTime = 14
Lighting.OutdoorAmbient = Color3.fromRGB(120, 120, 120)
end)
I might not have understood your explanation correctly.
Yeah you nailed it Preferably, have your local script within StarterGui.
2 Likes
Thank’s man, you saved my day
1 Like