I don't exactly know what the title should be. but still please help me

Alright so basicaly im making a backrooms game in which i got a int value that if its too low, the player die’s. to prevent the player from dying i made a tool. and it has a script but it doesn’t work. i don’t why.

local tool = script.Parent
local mouse = game.Players.LocalPlayer:GetMouse()
tool.Equipped:Connect(function()
	mouse.Button1Down:Connect(function()
		workspace.Script.Brain.Value = workspace.Script.Brain.Value + 50
	end)
end)
7 Likes

Try print debugging and then look what specifically is not printing, also here so you dont have to write it out:

local tool = script.Parent
local mouse = game.Players.LocalPlayer:GetMouse()

tool.Equipped:Connect(function()
    print("Tool equipped")
    
    mouse.Button1Down:Connect(function()
        print("Button clicked")
        local brainValue = workspace.Script.Brain.Value
        print("Before:", brainValue)
        
        brainValue = brainValue + 50
        workspace.Script.Brain.Value = brainValue
        
        print("After:", brainValue)
    end)
end)

3 Likes

idk why but it says that “equipped” is not a valid member of the tool.

1 Like

Is the script at the right place? (in tool)

yeah the script is in the tool.

1 Like

nevermind. i didnt see that the script was in the handle not the tool. fixed it now.

i noticed a problem. so i also got a script that every 2 seconds the brain.value goes down by 1. but when i activate the tool it just, goes back to normal.

do you know how i would fix that?

Just use .Activated, dont know why u using getmouse()
Hold on let me edit this

local tool = script.Parent
local mouse = game.Players.LocalPlayer:GetMouse()
tool.Activated:Connect(function()
		workspace.Script.Brain.Value = workspace.Script.Brain.Value + 50
end)

test this, wrote this here

Could you provide a code snippet?

1 Like

yeah alright. im just tryna figure out how to fix that.

whatchu mean by code snippet. im kind of new to scripting so i don’t know what you mean.

you mean like show the code???

heres the script in workspace

local brain = script.Brain
while true do
	wait(2)
	brain.Value = brain.Value - 1
	if brain.Value == 90 then
		game.Lighting.ColorCorrection.Brightness = -0.1
		if brain.Value == 80 then
			game.Lighting.ColorCorrection.Brightness = -0.2
			if brain.Value == 70 then
				game.Lighting.ColorCorrection.Brightness = -0.3
				if brain.Value == 60 then
					game.Lighting.ColorCorrection.Brightness = -0.4
					if brain.Value == 50 then
						game.Lighting.ColorCorrection.Brightness = -0.5
						if brain.Value == 40 then
							game.Lighting.ColorCorrection.Brightness = -0.6
						end
					end
				end
			end
		end
	end
end

Yes to see why the tool is getting normal again, just like you said

and here’s the script you’ve sent me before (idk why im sending this)

local tool = script.Parent

tool.Equipped:Connect(function()
	print("Tool equipped")

	tool.Activated:Connect(function()
		print("Button clicked")
		local brainValue = workspace.Script.Brain.Value
		print("Before:", brainValue)

		brainValue = brainValue + 50
		workspace.Script.Brain.Value = brainValue
		
		
			print("After:", brainValue)
		end)
	end)

what do you mean by goes to normal? as in, you use the tool and then it (sanity) no longer goes down anymore?

I recommend using this code (if it works)

local brain = script.Brain

while true do
    wait(2)
    
    -- Decrease brain value by 1
    brain.Value = brain.Value - 1
    
    -- Update lighting brightness based on brain value
    local brightnessValue = -0.1 * math.floor((100 - brain.Value) / 10)
    game.Lighting.ColorCorrection.Brightness = brightnessValue
    
    if brain.Value <= 0 then
        -- Handle the player's death or other consequences here
        break -- Exit the loop if brain.Value reaches 0 or below
    end
end

look. its goes down and lets say the int’s value is “200” and when i use the tool it becomes 250. but after the 2 seconds i goes down again and becomes 199 instead of 249.

sry for my english by the way.