So I am learning about scripting, and a created a bindable function script that doesn't seem to work properly. I created a list of players who could touch a brick to make its collision false, but the list doesn't work, it just kills me instead. Here are the two scripts:
part = script.Parent part.Touched:connect(function(hit) humanoid = hit.Parent:FindFirstChild("Humanoid") if humanoid then plrName = hit.Parent.Name ifadm = game.Workspace.AdmList.List:Invoke(plrName) if ifadmin == true then part.CanCollide = false else humanoid.Health = 0 end end end)
--1st script(inside brick)
adms = {"YouCheater"} script.List.OnInvoke = function(name) isadm = false for i, v in pairs(adms) do if name == v then isadm = true break end if isadm == true then return true else return false end end end
--2nd Script(with the bindable function)
2 problems:
1) You needed to pull lines 09-13 of the second script out of the for
loop, since it was returning an answer before reaching the end of the adms
table.
2) In line 07 of the first script, you store the result of the invoked function in variable ifadm
but are checking a different variable ifadmin
on the next line to decide to open the door or kill the player. ifadmin
was a typo, so the variable was nil
, causing the if
statement to evaluate to false
and always skip to line 11.
Here is the fixed code without any other edits:
-- First Script part = script.Parent part.Touched:connect(function(hit) humanoid = hit.Parent:FindFirstChild("Humanoid") if humanoid then plrName = hit.Parent.Name ifadmin = game.Workspace.AdmList.List:Invoke(plrName) if ifadmin == true then part.CanCollide = false else humanoid.Health = 0 end end end) -- Second Script adms = {"YouCheater"} script.List.OnInvoke = function(name) isadm = false for i, v in ipairs(adms) do if name == v then isadm = true break end end if isadm == true then return true else return false end end
I would also add a debounce to your Touched
event handler, since it will fire a lot just from one player running into the door.