My BindableEvent from ServerScriptService Script -> BindableEvent -> Workspace script returns nil even though the returned variable is defined. I can guarantee that as the variable has been pre-checked in a print() before being sent. But once the server script receives it, it suddenly becomes nil.
-- Workspace "MapHandler"
map = ReplicatedStorage:WaitForChild("Remotes"):WaitForChild("EndMapVote"):Fire()
if map == nil then
print("map was nil: ")
print(map)
end
The difference between BindableEvents and BindableFunctions is that BindableFunctions act something like functions, and BindableEvents act a bit like functions except the fact that you do not await for a response.
To clarify however, you must always return with a BindableFunction as otherwise it infinitely stalls and BindableFunctions cannot be ‘connected’ to, it instead expects a function as an input.
So if I read your replies correctly, the purpose of any sort of Event is to get fired (with or without parameters) from somewhere, while any sort of Function is to get fired (with or without parameters) from somewhere AND return one or more variables.
It appears to be working! Just so I don’t create too many posts, is it possible you could help me with this related line of code?
local mapname = string.gsub(map, "_", " ")
local mapname = string.gsub(map, "And", "&")
print(mapname)
choosemap = ReplicatedStorage:WaitForChild("Maps"):FindFirstChild(mapname)
if ReplicatedStorage:WaitForChild("Maps"):FindFirstChild(mapname) == nil then
print("could not find given map: ".. mapname)
end
it keeps not finding the given map because the _ and the And never gets replaced. Let me give you an example:
Default_Map has been assigned to mapname
Default_Map should change to Default Map but never does.
Script returns "Could not find given map: Default_Map".
Thanks in regards. Don’t worry, I won’t prioritize this 'cause the subject is something else.
You’re reassigning mapname twice and not using mapname for the gsub second
local mapname = string.gsub(map, "_", " ")
mapname = string.gsub(mapname, "And", "&")
print(mapname)
choosemap = ReplicatedStorage:WaitForChild("Maps"):FindFirstChild(mapname)
if not ReplicatedStorage:WaitForChild("Maps"):FindFirstChild(mapname) then
print("could not find given map: ".. mapname)
end
Wow, thank you both for answering at such a reliably consistent speed! I wish I could solute you both as you pretty much point out the same things but differently formulated each time.
It all worked in the end, so thank you both for participating in this case!
-Mathe