I made a script that kills someone if their name is not the same as a model's name (after 2 letters,) however, the script continues to kill everyone, regardless of their name. There are no errors. Here is the script:
script.Parent.Touched:connect(function(hit) if not hit.Parent:FindFirstChild("Humanoid") then script.Parent.hit:Play() hit:Destroy() else local nm = hit.Parent.Parent.Name local tb = script.Parent.Parent.Name if nm ~= string.sub(tb,3) then hit.Parent.Humanoid:TakeDamage(100) script.Parent.hit:Play() wait(1) end end end)
According to the documentation of string.sub:
The call string.sub(s,i,j) extracts a piece of the string s, from the i-th to the j-th character inclusive.
You called it as string.sub(tb,3)
, which would return a string composed of the third character and everything after it. To get only the third character, you would have to do string.sub(tb, 3, 3)
.
note: I noticed that you edited it from tb:sub(3) to string.sub(tb, 3). The first way also works.