Yea this isn’t good practice. Instead to define the character you should do:
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
--First off we define the chartacter by doing player.Character.
--If that is nil (which there is a high chance since the character hasn't loaded in yet)
--Then we wait for the .CharacterAdded to fire by doing .CharacterAdded:Wait() which will fire when the character has loaded in.
local humanoid = character:WaitForChild("Humanoid")--Waiting for the humanoid since there is a chance all the parts inside the character haven't loaded in yet.
It is not working because there is only 1 player in the game. It will only change the ColorCorrection if it’s not the player who fired. But since you’re the only one in the game, it doesn’t change. To fix this do:
game.ReplicatedStorage.Event.OnServerEvent:Connect(function(playerWhoFired)
game.Workspace.Sound2:Play()
game.Lighting.ColorCorrection.Saturation = -1
game.Lighting.ColorCorrection.Contrast = -2
for i, player in pairs(game.Players:GetPlayers()) do
if player ~= playerWhoFired then --
player.Character.HumanoidRootPart.Anchored = true
end
end
wait(5)
game.Lighting.ColorCorrection.Contrast = 0
game.Lighting.ColorCorrection.Saturation = 0
end)
This way it will play the sound and change the color correction right when it gets fired.
No problem. Another thing you should not is that this is very exploitable. I could just join the game and fire that event multiple times without a cooldown/check since exploiters are able to do that.
game.ReplicatedStorage.Event.OnServerEvent:Connect(function(playerWhoFired)
game.Workspace.Sound2:Play()
game.Lighting.ColorCorrection.Saturation = -1
game.Lighting.ColorCorrection.Contrast = -2
for i, player in pairs(game.Players:GetPlayers()) do
if player ~= playerWhoFired then --
player.Character.HumanoidRootPart.Anchored = true
end
end
wait(5)
game.Lighting.ColorCorrection.Contrast = 0
game.Lighting.ColorCorrection.Saturation = 0
wait(timeTillUnfreeze)
for i, player in pairs(game.Players:GetPlayers()) do
player.Character.HumanoidRootPart.Anchored = false
end
end)