I came up with an idea to make a ModuleScript that calls a method that finds the Humanoid of a player and kills it...
(BTW apologies for the lengthy question)
I've been trying to test this idea in a regular script that doesn't kill nor is a modulescript. Here's the script I've got.
function getData(self) -- function with "self"; a.k.a. le method that I am hoping to get to function
if self.Parent == nil then -- if part has already been destroyed
warn("Part has no parent") -- warn (I'm too lazy to use error() lol)
end
print("Getting data on part...") -- this is just for fun
wait(1)
print("BEEP BOOP")
wait(0.3)
print("The selected part's name is "..tostring(self.Name)) -- Print the Name of the part
wait(0.4)
print("The selected part's FullName is "..tostring(self:GetFullName())) -- get the full name
wait(0.4)
print("The part's BrickColor is "..tostring(self.BrickColor)) -- get le brickcolor
wait(0.4)
print("The part's RGB color is "..tostring(self.Color)) -- get RGB
wait(0.4)
print("The part's Reflectance is "..tostring(self.Reflectance))
wait(0.4)
print("The part's Transparency is "..tostring(self.Transparency))
wait(0.4)
print("And finally, the part's position is... *que drumroll*")
wait(1)
print("..."..tostring(self.Position).."!!!!!!!1") -- finally le position
end
wait(1) -- countdown
print("3")
wait(1)
print("2")
wait(1)
print("1")
wait(1)
game.Workspace.i_am_a_part:getData() -- attempt to call the function as a method on the workspace part
But I get from the output:
>> getData is not a valid member of Part
When what I expect is:
>>3
>>2
>>1
>>Getting data on part...
>>BEEP BOOP
>>The selected part's name is i_am_a_part
>>The selected part's Full Name is game.Workspace.i_am_a_part
>>The part's BrickColor is Medium stone grey
>>The part's RGB color is 163, 162, 165
>>The part's Reflectance is 0.7
>>The part's Transparency is 0.3
>>And finally, the part's position is... *que drumroll*
>>...-6, 0.5, 4!!!!!!!1
However... If I run this in the same script instead:
game.Workspace.i_am_a_part:Destroy() -- destroy the part
wait()
local partCheck = game.Workspace:FindFirstChild("i_am_a_part")
if partCheck then
print("Part not destroyed")
else
print("Part destroyed.")
end
I immediately get the output: Part destroyed.
------------CONTINUED-------------
I've kept this question in my browser un-posted for a long time, hoping I could make :getData() function without posting this, but so far I have not succeeded in doing so, so I guess I'll just post it...
Here is the script at the point I posted this:
local Game = {} -- table to imitate "game"
local mt = {
__index = function(self, i) -- make sure Instances exist in the table when called
self[i] = i -- Attempt to set the value of the object to the Instance
print(self[i]) -- meant to print the name of the instance
print(self[i].ClassName) -- meant to print the ClassName of the instance
-- iT = i.."ch" (These two lines were me thinking of spreading the metatable's code to the table... rejected it though. Wasn't gonna work anyways)
-- iT = {}
return self[i] -- return the instance
end
}
setmetatable(Game, mt) -- set the metatable of Game to mt
function getData(self) -- ye olde method attempt
if self.Parent == nil then
warn("Part has no parent")
end
print("Getting data on part...")
wait(1)
print("BEEP BOOP")
wait(0.3)
print("The selected part's name is "..tostring(self.Name))
wait(0.4)
print("The selected part's FullName is "..tostring(self:GetFullName()))
wait(0.4)
print("The part's BrickColor is "..tostring(self.BrickColor))
wait(0.4)
print("The part's RGB color is "..tostring(self.Color))
wait(0.4)
print("The part's Reflectance is "..tostring(self.Reflectance))
wait(0.4)
print("The part's Transparency is "..tostring(self.Transparency))
wait(0.4)
print("And finally, the part's position is... *que drumroll")
wait(1)
print("..."..tostring(self.Position).."!!!!!!!1")
end
wait(1)
print("3")
wait(1)
print("2")
wait(1)
print("1")
wait(1)
Game.Workspace.i_am_a_part:getData() -- will it work? o wait, i'm cursed, it'll never work
In this current state, when run, the output prints Workspace when the last line runs - we want that. But then after that, it prints nil. I presume this means that it's calling the table object... but not the instance? Like, weird. Also, then it errors Workspace.Script:44: attempt to index field 'i_am_a_part' (a nil value). I do see why though.
This is the part that confuzzles me though: If I change self[i] = i to self[i] = game.i, it simply errors >>i is not a valid member of DataModel. Soo... I guess that's a good stopping point.
(Note: This is my first question, so I apologise for any inconveniences.)
RESPONSE TO LONG-AGO FIRST ANSWER: I don't see why I can't just finish the script and keep going on and implement it as a method (pun simultaneously intended and unintended) to kill players easily; I've already made progress that clearly can be progressed on. Also, I barely even can understand the code given (to clarify, the best game I've created is basically just an average baseplate, poor decoration, smolboi-level scripting, and several free models (generally of guests)). I mean... i just wanna... finish my script...
2:52 - Script, line 98: sweetkid01 has died

2 comments
Ik, but methods normally only work with tables, that's my issue here
once you destroy or remove the part, you can't gather information from it or make any changes (it will always return nil). One thing you can do is clone the part before destroying it. The clone will remain nil until you set it's parent.