Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 3 years ago
Edited 3 years ago

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)
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 imKirda 4491 — 3y
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. johncrazy1rb 11 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

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)
Ad

Answer this question