I need help I'm wanting to make a system that can decet heat from bricks I place around the map and take health but the problem is it giving me an error about Workspace not vaild member as Workspace. Any help will be nice.
My Code
while true do local plr = script.Parent.Parent local range = 5 local brick = game.Workspace.Heat.Heat local Heat_F = game.Workspace.Heat for _,Heat_F in pairs(Heat_F:GetChildren()) do local myDist = 0 myDist = (game.Workspace[plr.Name].Torso.Position - game.Workspace.Heat[Heat_F].Position).magnitude if myDist > 5 then print(myDist) myDist = 0 else print('Too Far') end end end
Error Code
07:16:08.804 - Workspace is not a valid member of Workspace 07:16:08.805 - Stack Begin 07:16:08.806 - Script 'Workspace.Player1.Heat_Detector', Line 10 07:16:08.806 - Stack End
Hello, BFIofficer9901!
I know why your script isn't working!
On line 9 you had to use "[Heat_F.Name]"
-- Local Script -- I turned your script into R15 and R6 cuz I use R15 local Torso = game.Players.LocalPlayer.Character:FindFirstChild("Torso") if not Torso then Torso = game.Players.LocalPlayer.Character:FindFirstChild("UpperTorso") end while true do wait(1) local plr = script.Parent.Parent local range = 5 local brick = game.Workspace.Heat.Heat local Heat_F = game.Workspace.Heat for _,Heat_F in pairs(Heat_F:GetChildren()) do local myDist = 0 myDist = (game.Workspace[plr.Name][Torso.Name].Position - game.Workspace.Heat[Heat_F.Name].Position).magnitude if myDist < 5 then -- If it's ">" it will test if is far away from it print(myDist) myDist = 0 else print('Too Far') end end end
Good Luck with your games!
I am super confused. But, well. Try changing it to this:
while true do local plr = script.Parent.Parent local range = 5 local brick = game.Workspace.Heat.Heat local Heat_F = game.Workspace.Heat for _,Heat in pairs(Heat_F:GetChildren()) do local myDist = 0 myDist = (plr.Character.Torso.Position - Heat.Position).magnitude if myDist > 5 then print(myDist) myDist = 0 else print('Too Far') end end end