Error with task.spawn()

–[[ This errors:
16:02:05.972 Players.matt1020304050.PlayerScripts.Music-Water Controller:44: invalid argument #1 to ‘spawn’ (function or thread expected) --]]

function waterEffect(inside, outside)
	
end
task.spawn(waterEffect(true,false))
1 Like

You need to call task.spawn like this.

task.spawn(waterEffect,true,false)

pro tip: you can use pcalls like that as well.

pcall(workspace:FindFirstChildOfClass("Part").SetNetworkOwner, FindFirstChildOfClass("Part")) -- sets the network owner of a part to nil in a pcall.
3 Likes

Sorry what’s the pcall for in this post?

Just a tip if you use pcalls to structure them like that since it looks cleaner than doing it like this.

 local part = workspace:FindFirstChildOfClass("Part")
pcall(function()  
    Part:SetNetworkOwner()
end)  -- looks ugly

pcall(Part.SetNetworkOwner, Part) -- looks neat
2 Likes