Quantcast

How to change daylight when touching a part?

Help me I need it for my map.

im pretty sure this will work (put script in the part not eventstring)

script.Parent.Touched:Connect(function(hit)
  if hit then
	game.Lighting.TimeOfDay = 23
	end
end)

wait there needs to be

    end
end)

bc i’ve been doing button functions on my map and only have been adding one “end”, like this

button function script
end

what i sent works

i tried it

You can do that then if anything touches it, it would react. Like if a random block touches it the code would run so it should be more like

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then -- checks if the item that touches it contains a humanoid
		game.Lighting.TimeOfDay = 23 -- doing the thingy
		print("Player ".. hit.Parent.Name .." has touched '".. script.Parent.Name .."'") -- ignore this
	end
end)

But it would change if a player was to repeatedly touch it and so you should add a debouce or destroy the script. What i mean is if changes from 23 to example 10 then someone else touches it again, it would ruin everything so
debounce is like you can wait a few second or anytime till they can touch it and it would react again.
But a better one so it would not react again would be to :Destroy()
So like

-- Touch Script
local db = true

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		if db == true then
		hit.Parent:BreakJoints()
		print("Player ".. hit.Parent.Name .." has touched '".. script.Parent.Name .."'")
		db = false
		wait(3) -- how long till it would react again
		db = true
		end
	end
end)

Or you can just do

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then -- checks if the item that touches it contains a humanoid
		game.Lighting.TimeOfDay = 23 -- doing the thingy
		print("Player ".. hit.Parent.Name .." has touched '".. script.Parent.Name .."'") -- ignore this
script:Destroy()
	end
end)

I think my post was not needed :man_shrugging: