Edit: That is the output of the print
I’m not fully understanding the question… could you explain it further?
Sorry, ive clarified thats the output of the print in the script
You are trying to print a function that is why.
How about you do this instead:
-- LOCALSCRIPT --
local HRP = game.Players.LocalPlayer.Character.HumanoidRootPart
HRP.Touched:Connect(function(hit)
print("hi")
end)
That happened to me once, Roblox for some reason does it. You are trying to print a function for some reason, out is caused by this line here:
print(idk()) This makes no sense and is a big no no when doing this.
Instead, call the function rather than printing it.
Here is an example:
idk() rather than print(idk()).
That is most likely the error, I got similar results when doing that, call the function, rather than trying to print it.
Its suppose to be a function that gets the current room by checking if the HumanoidRootPart is touching a “InRoom” part, you can see it commented out.
I can see that. That is not your error though.
Well, you can just add that after the print(“hi”) in my bit of code.
You are trying to print a function, why not just call it? Using this idk() rather than trying to print it.
Plus, return statements should not return a string, it usually returns a variable.
i want to make some code that gets the current room the player is standing in (for later, like displaying in a gui for multiple use cases), its suppose to return touched.Parent but it doesnt print it out for some reason even though im returning it
simply putting the print statement in the code makes no sense for my case since i need the room i am in to return to a Textlabel or something
Also im not printing out the table itself because i have print(idk()) instead of print(idk). Im trying to print out the return value
There’s a little mistake in that script, the function called idk doesn’t return any value, thus print prints nothing. You created a new function inside of idk (and connected it to a Touched event) that returns a value, but you never told idk to itself return a value. Getting it to work the way you’re currently doing it will be a little weird and really confusing, a better idea would be to just use GetTouchingParts to get a table with all the parts touching HumanoidRootPart and then checking if one of those parts are named “InRoom.”
function idk()
local HRP = game.Players.LocalPlayer.Character.HumanoidRootPart
local TouchingParts = HRP:GetTouchingParts()
for _, Part in pairs(TouchingParts) do
if Part.Name == "InRoom" then
return "hi"
end
end
end
You’re actually not returning anything, the return statement you put in the Touched function makes the function inside of idk return a value, it doesn’t make idk itself return a value
thank you friend, that is actually a lot simpler
This isn’t a bug. The function idk isn’t returning anything. If you want it to print hi, the return needs to be the last part of a reachable scope in your function. Returning anything to an RBXScriptConnection is pointless because they aren’t callbacks or functions and don’t need to be given anything back.
local function idk()
local humanoidRootPart = game:GetService("Players").LocalPlayer.Character.HumanoidRootPart
humanoidRootPart.Touched:Connect(function (part)
-- This isn't supposed to return anything. Don't put returns here.
end)
return "hi"
end
while true do
print(idk())
wait()
end
Are you just testing? I’m really curious to know why you’re connecting a touched event every ~0.03 seconds (assuming the task scheduler doesn’t defer any of your threads to the next frame).
yeah i was just testing, since i was confused on why it wasnt working properly. I didnt understand that it was returning to the unintended function
Plus, return statements should not return a string, it usually returns a variable.
You are trying to print a function for some reason, out is caused by this line here:
print(idk()) This makes no sense and is a big no no when doing this.
Instead, call the function rather than printing it.
This is not correct. If you try to “print a function” as you call it, it will print whatever value is returned or nil. You can return anything; a string, a variable, or an equation etc
While that does work, and hence why it’s the solution, Region3 would be the most optimized way of doing it.
- You aren’t creating instances to deal with touching parts.
- You don’t have ugly workarounds with building in Studio.
- It’s more accurate and less prone to logic errors.
- It uses less memory.
Region3 is comparable to Raycasting; you can call it many times in a short timeframe with minimal performance impact.
Information on Region3:
How to use Region3 to get parts in an area:
As a side note, you can also improve the way you check parts in a room in another area.
You seem to check the part’s name, when instead, you can use CollectionService.
CollectionService allows you to add “tags” to instances to easily read and get them.
