Hey guys, I'm stuck in this script

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.

Also, the lighting isn’t changing, as you can see in my Serverscript, the sound isn’t playing aswell. Did I make a mistake?

1 Like

Did you make a “ColorCorrection” effect in lighting before you changed it?

Nope, the colorcorrection is all 0.

Have you tried enabling the colorcorrection?

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.
1 Like

Thank you so much! It now works. I’ll now test it out.

1 Like

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.

1 Like

Oh, alright. One more thing, how would you make it so they get unanchored after like… 5 seconds?

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)

Simple

1 Like

Thank you. I am pretty new to scripting, so this’ll help alot.

1 Like