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

Can't change a specific player's Lighting.ExposureCompensation | attempt to index nil with 'Name'?

EDITED

Alright so I switched my LocalScript to RemoteEvent but I've encountered a script error 'attempt to index nil with name'.

What I'm trying to achieve: I want that when a player touches a specific part in the game, a script inside the part activates and sends a RemoteEvent signal to the player that touched the part, and the LocalScript inside the player changes the Lighting.ExposureCompensation

Server script:

function Touch(hit)
	local part = script.Parent
	local Players = game:GetService("Players")
	local player = Players:GetPlayerFromCharacter(part.Parent)
	local playername = player.Name
	game.ReplicatedStorage.ExposureFired:FireClient(playername)
	end
	script.Parent.Touched:Connect(Touch)

Client/Local Script:

local function detected()
	local entering = -2
	local exit = 0
	local lighting = game:GetService("Lighting")
	if lighting.ExposureCompensation == entering then
		lighting.ExposureCompensation = exit
	elseif lighting.ExposureCompensation == exit then
		lighting.ExposureCompensation = entering
	end
	end

game.ReplicatedStorage.ExposureFired.OnClientEvent:Connect(detected)

2 comments

0

Local Scripts do NOT run in workspace, the best directory for them is StarterPlayerScripts. Here it says all the places where local scripts run: https://developer.roblox.com/en-us/api-reference/class/LocalScript

0

Thank you for letting me know, I've edited the thread now since I've tried RemoteEvent instead but I still have a problem with the script.

1 answer

SOLVED:

I asked this question in a developer discord server and they gave me a solution.

Code by Senko-san#0001:

local lighting = game:GetService("Lighting")

game.Workspace.Changer.Touched:Connect(function()
	local entering = -2
	local exit = 0

	if lighting.ExposureCompensation == entering then
		lighting.ExposureCompensation = exit
	elseif lighting.ExposureCompensation == exit then
		lighting.ExposureCompensation = entering
	end
end)

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