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

How would I go about making this script client sided?

local LightKit = game.Lighting
local OtherValues = game.Lighting.ColorCorrection
local Glare = game.Lighting.Bloom
local LKIT = script.Parent
local function PlayerTouched(Part)
	LightKit.Brightness = 2.08
	LightKit.Ambient = Color3.new(0, 0, 0)
	LightKit.OutdoorAmbient = Color3.fromRGB(49, 49, 49)
	LightKit.ShadowSoftness = 0.08
	LightKit.GlobalShadows = true
	LightKit.EnvironmentDiffuseScale = 0
	LightKit.EnvironmentSpecularScale = 0
	OtherValues.Brightness = -0.2
	Glare.Intensity = 0
	Glare.Size = 9
	Glare.Threshold = 1
	--print("Lighting changed. Please comment out until I can implement a debounce.")
end

LKIT.Touched:connect(PlayerTouched)

This is my code. The purpose of this script is to change the lighting (called a Lightkit in this case because of the other things like bloom) I need this script to be client sided so the light is not influenced by other players (say, the player is in a certain area and another player touches a trigger in a different area, causing the light to change for everyone.)

2 answers

✓ Accepted answer

I suggest you use a remote event, e.g put a remote event in replicated storage called "fire"

Server script:

LKIT.Touched:Connect(function()
game.ReplicatedStorage.fire:FireClient()

Local script in StarterGUI

local LightKit = game.Lighting
local OtherValues = game.Lighting.ColorCorrection
local Glare = game.Lighting.Bloom
local function PlayerTouched(Part)
    LightKit.Brightness = 2.08
    LightKit.Ambient = Color3.new(0, 0, 0)
    LightKit.OutdoorAmbient = Color3.fromRGB(49, 49, 49)
    LightKit.ShadowSoftness = 0.08
    LightKit.GlobalShadows = true
    LightKit.EnvironmentDiffuseScale = 0
    LightKit.EnvironmentSpecularScale = 0
    OtherValues.Brightness = -0.2
    Glare.Intensity = 0
    Glare.Size = 9
    Glare.Threshold = 1
    --print("Lighting changed. Please comment out until I can implement a debounce.")
end

game.ReplicatedStorage.fire.OnServerEvent:connect(PlayerTouched)

Please accept this answer if it works

4 comments

0

In the console, I get "OnServerEvent can only be used on the server"

0

Change line 19 to: game.ReplicatedStorage.fire.OnClientEvent:connect(PlayerTouched)

0

That worked, but I now get "Argument 1 missing or nil" in the server script.

0

Oh sorry, I forgot, in the server script, it is meant to be: game.ReplicatedStorage.fire:FireClient(player)

To add, here's how I fixed the server-side script.

local LKIT = script.Parent

LKIT.Touched:Connect(function(hit)
local p = game.Players:GetPlayerFromCharacter(hit.Parent)
    if p then
game.ReplicatedStorage.fire:FireClient(p)

	end
end)

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