!strict problem

so I have a module script that returns a player and playerCharacter within a callback function

Module script :

if canLoop == true then
                    playerObject.CharacterAdded:Connect(function(modelObject:Model)
                        callback(playerObject, modelObject)
                    end)
                else
                    playerObject.CharacterAdded:Once(function(modelObject:Model)
                        callback(playerObject, modelObject)
                    end)
                end

in the serverScript I get this error

image

yes i’ve looked around for a problem like this and none of them show a callback function so this is new and I’m using --!strict I don’t think this is a bug but if it is let me know

and also yes I’ve used all the other ways to see if I can bypass this error none worked the error part I believe is this

 function(playerObject:Player, modelObject:Model)
1 Like

At first glance, I’m unsure.

But, --!strict is not real strict typing and I’ve had some odd problems with it (crap like type 'string' could not be converted into 'string | string | number | buffer | thread | bool | ....' and it just kept going). In my opinion, if you want strict typing use roblox-ts. But, if you want to stick to --!strict and Luau, use the :: operator to cast types to other types. For instance, x :: any and it will work. I don’t recommend it as a long-term solution, but should be enough to hold you over until someone who has more experience wrangling --!strict can help.

1 Like

show full error code please
char limit

that is the full error the script runs just fine but I get that,

I have used the :: and I still got the same error is it a bug then?

It is strict typing if you are running a native code.
Roblox-ts is a joke that is even worse than your analogy

i need to know function you are running.
You provided no information what so ever and more so cropped error code
image

this is the entire module side that gets this error

function module:setPlayerHook(canLoop:boolean, callback:(Player, Model) -> (Player, Model))
    if not canLoop or  not callback  then
        warn("nil passed returning.")
        return
    else
        if typeof(canLoop) ~= "boolean" or typeof(callback) ~= "function" then
            warn("wrong type")
            return
        else
            playerService.PlayerAdded:Connect(function(playerObject:Player)
                if canLoop == true then
                    playerObject.CharacterAdded:Connect(function(modelObject:Model)
                        callback(playerObject, modelObject)
                    end)
                else
                    playerObject.CharacterAdded:Once(function(modelObject:Model)
                        callback(playerObject, modelObject)
                    end)
                end
            end)
        end
    end
end

Not sure then. Like I said, --!strict is a trap in Luau, if you want strict typing you should try out roblox-ts. I’ve had too many problems with --!strict to trust it with anything.

I don’t understand this. Do you mean --!native? If so, I haven’t used it too much so you could be correct.

Sure, it’s slower than Luau because it compiles to Luau, but OP still gets the strict typing he wants, plus a far better type system. I don’t want to argue with you as to not clutter the thread.

so far I’ve gotten --!strict to work just fine its jus this one error that will not go away no matter what

1 Like

Why do you declear function with : ?
Well obviously it will not work
its equialent to module.setPlayerHook(self,canLoop:boolean, callback:(Player, Model) → (Player, Model))
Essentially you create “invisible” argument self that you can clearly see when calling that

Yes, that’s my point. I’ve gotten “this one error” too many times. I’ve just given up on --!strict and if I want strict typing I’ll use TypeScript. I don’t use it for performance-critical code, though.

wdym by “: ?” there is no : ? that I can see

i fixed your code and now it should work:
Dont declear functions with “:” instead of “.” if you are not using argument self; and even if you do i still would avoid doing that

local Players = game:GetService("Players")

local module = {}
function module.setPlayerHook(canLoop:boolean, callback:(Player, Model) -> (Player, Model))
	if not canLoop or  not callback  then
		warn("nil passed returning.")
		return
	else
		if typeof(canLoop) ~= "boolean" or typeof(callback) ~= "function" then
			warn("wrong type")
			return
		else
			Players.PlayerAdded:Connect(function(playerObject:Player)
				if canLoop == true then
					playerObject.CharacterAdded:Connect(function(modelObject:Model)
						callback(playerObject, modelObject)
					end)
				else
					playerObject.CharacterAdded:Once(function(modelObject:Model)
						callback(playerObject, modelObject)
					end)
				end
			end)
		end
	end
end

Still giving the type pack error and reason I had module: is because I heard you add : for if it takes values and . if it doesn’t but all my functions usually take a value

that complete misunderstanding as to how function declaration works…

Please enable new type solver in beta features that could help.
Code does not error for me in a strict mode for example.

1 Like

Alright and I do have new type solver on

no.
That not how things work.
If you do get confused with metatable OOP you can use alternative (that would be better in your case)
Just dont use : when declearing function becouse it creates unneeded (in your case) argument.

Could you please show where you call this function?
That could be the reason as to why it errors

1 Like

I’ve used OOP before and I just heard you use : for values and . for none ones I changed it and now they use . but let me change something its a bit of a mess now

Here’s clarification on what they mean.

function module:myFunc()
    print(self) -- This variable here is implicitly defined when using :
end

module.myFunc() -- Does not work because you aren't providing self
module:myFunc() -- Should, because you are implicitly providing self

Self is the table itself.