this = script.Parent function fademodel(part, modelname) if part ~= nil then model = game.Lighting.Models:findFirstChild(modelname) modelchildren = model:GetChildren() tempmodel = Instance.new("Model") tempmodel.Name = model.Name tempmodel.Parent = game.workspace.FadeModelTest.Models for i, v in ipairs(modelchildren) do local t = v:clone() local temp = v.CFrame t.Parent = tempmodel t.CFrame = temp wait(.25) end end end print("here") this.Touched:connect(fademodel(part))
This is my script. I'm trying to make a part that, when you touch it, it will bring a model out from the lighting but in a more light on resources kind of way. The issue is, that this line: this.Touched:connect(fademodel(part))
is throwing the error: Attempt to connect failed: Passed value is not a function
I've got a feeling it's just some dumb typo that I can't seem to find, but it might be something else. Any help would be appreciated.
Touched events have one built in parameter. It is built in, so you do not have to define it with an argument. This parameter is hit or part, which is automatically equal to the part that hit the brick. Don't try adding other parameters, as it probably won't work right. You should also check if the part that touched the brick is truly a player. For this we can use the GetPlayerFromCharacter() method.
Also, you're basically creating a clone of the model you put in Lighting, and putting it in workspace. But why would you do it the way you're doing it, instead of just using the Clone()
method? So,
this = script.Parent modelname = "modenamehere" function fademodel(part) if game.Players:GetPlayerFromCharacter(part.Parent) then local clone = game.Lighting[modelname]:Clone() clone.Parent = game.Workspace.FadeModelTest.Models end end print("here") this.Touched:connect(fademodel)
Hope i helped!