I’m making a game where when the player enters the house, their lighting effects change, but for people outside the house, everything is normal. To detect if a player is inside, I want the game to check if they are touching a certain brick.
How would I do this so that ONLY the players touching the brick have the lighting effects applied to their screen?
You would run the event:
workspace.part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
--do stuff locally, so only for 1 player
end
end)
but in a local script, and in staterGui or starterPlayerScripts because local scripts don’t run in workspace.
this actually helps me with my Marble run game, however, do you know how to make it so it checks for local parts, and it also works with multiple parts, in a folder
thank you for that!
Do you know how to make it so it only does it when the player is touching the brick, otherwise, it will stop?
like using an if else statement or something like that?
So like if player is touching the brick, run all the scripts. Else, stop the scripts. Somehting like that?
since it’s a local script, it’s only going to check parts locally. In folders, you would simply add this to the event:
for i,v in pairs (folder:GetChildren()) do
v.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
--do stuff locally, so only for 1 player
end
end)
same thing as before, but add Magnitude to it.
local db = false
workspace.part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if db == true then return end
db = true
--do stuff locally, so only for 1 player
local magnitude = (hit.Position - workspace.part.Position).Magnitude
repeat
wait(1)
--do more stuff, infinitively until player stops touching
local magnitude = (hit.Position - workspace.part.Position).Magnitude
until magnitude > --[[part size of x/z axis divided by 2, or any distance so that it stops--]]
db = false
end
end)
for reference: Vector3 | Documentation - Roblox Creator Hub
GOT IT!
Thank you so much!
3 0 c h a r a c h t e r res dwfha 'ogf
The only issue I have is that everything stops after like 1 seconds, because it thinks that the player is no longer touching the brick.
you can increase the number compared in
until magnitude >
to something bigger
Very simple, if your referring the sky, blues and other stuffs relating to lighting, add those in camera or workspace.CurrentCamera. This will only take effect of locally and not server. If you place these in the lighting property, everyone will see the same changes.
There’s an issue with this code. If a random humanoid model (NPC) touches the part, this would result in an error. I recommend using Players:GetPlayerFromCharacter(part) to collect the player.
For example:
local player = game:GetService'Players':GetPlayerFromCharacter(touchedpart.Parent)
if player then
RemoteEvent:FireClient(player) -- or RemoteFunction:InvokeClient(player) if there's an OnClientInvoke registered for this remote function in a local script
end