I’d create an invisible part that you can cast a ray above the character to so that if that part is hit, then you are considered under that bulb. The best part about this is that if you are not directly under the light, you are at least within the vicinity to meet the cast point of the light.
Wouldn’t that require multiple scripts, one inside each of the parts that is casting a ray?
No, you would just cast a ray from the character to about as many studs upward it will be to reach a bulb, and if it does hit a part that is either named BulbVicinityPart
or something of that matter, then you should do whatever you want through there. This shouldn’t require a vast amount of scripting.
Ah okay I understand, I will try that thank you!
I dont know if that would be so easy because it needs an event to send a message to the server that the monsters will like walk away if it hit the invisible block
You can cast the ray on the server for each character, so long as your player count does not exceed something like 20 players. Raycasting is costly to the performance of a game, so if you keep it to 20 or under, you should be fine doing it from the server.
I’ll further add that raycasting essentially not only takes that lookahead point but also requires that you multiply it by the distance in studs for it to go, so you can tell the ray that it should only cast from X-5 to X+5, which should be 10 studs and no further.
oh ok i understand this i think that the information you just provided works
have you tried something like this not completely what you want but you can learn from it
Thank you, that is very helpful and I will look into it.
Should I use RenderStepped in order to constantly fire the raycast?
check if they are under a street light is a reasonable approach. Here’s a summary of the suggestions:
- Create an invisible part (named something like “BulbVicinityPart”) under the street light.
- Use a script to cast a ray from the player to the vicinity above them.
- If the ray hits the “BulbVicinityPart” or any designated part, trigger the desired behavior (monsters stop chasing, etc.).
This method minimizes the need for multiple scripts or complex setups, and it should be performance-friendly. Just make sure to handle the events efficiently, especially if your game might have a higher player count.
Alright, the player count will probably be set to around 12 so I should be good.
ok so tell me what do you want to know
RenderStepped
is only available on the client. If you’d like to optimize for performance, you should probably cast rays from the character to the bulb from the client and then communicate with the server with a RemoteEvent so that the server understands that you want to do something.
I created the raycast in StarterCharacterScripts, but you are saying that I should cast the ray from the server instead using only one script that way it doesn’t require a remote event? Sorry I am a bit confused since I am not the best at scripting.
Below is an example script in Lua for Roblox that you can use as a starting point. This script assumes that you have an invisible part named “BulbVicinityPart” placed under each street light.
local BulbVicinityPartName = "BulbVicinityPart"
-- Function to check if the player is under the light
local function isPlayerUnderLight(player)
local character = player.Character
if character then
local humanoid = character:FindFirstChildOfClass("Humanoid")
local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
if humanoid and humanoidRootPart then
local rayStart = humanoidRootPart.Position
local rayDirection = Vector3.new(0, 1, 0) -- Upward direction
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
raycastParams.FilterDescendantsInstances = {player.Character} -- Exclude the player's character
local rayResult = workspace:Raycast(rayStart, rayDirection, raycastParams)
if rayResult then
local hitPart = rayResult.Instance
return hitPart and hitPart.Name == BulbVicinityPartName
end
end
end
return false
end
-- Example: Check if a player is under the light
local player = game.Players.LocalPlayer -- Replace with the actual player you want to check
if isPlayerUnderLight(player) then
print("Player is under the light!")
else
print("Player is not under the light.")
end
This script defines a function isPlayerUnderLight
that checks if a given player is under the light by casting a ray from the player’s position upwards and checking if it hits the “BulbVicinityPart.” You can integrate this script into your game and adapt it according to your specific requirements.
Oh wow thank you, where would I place this script?
People visit the Developer Forum to get real-world, human responses, and you’re using ChatGPT.
i am still helping so and i do not only use chatgpt like you can say that to with your very long responses with words a human wouldnt say
serverscript or starterplayerscripts