How do you make the game randomly choose from two parts and kill any humanoid that is on the part???
local function whatever()
local partone = game.workspace.part
local parttwo = game.workspace.part
local screen = math.random(1,2)
if screen == 1 then
game.workspace.part --what u want it–
print(“1”)
elseif screen == 2 then
game.workspace.part
print(“2”)
end
end
end
Hope that helps but put your part where it says part and where it says game.workspace.part put what you want it to do.
Thank you but could you explain what the script means and how it kills any humanoid on the part?
You create the function then you tell the script what everything is then I’m telling the script to do pick between 1 and 2 with math.random then I’m checking if it picked 1 or 2 then I just do if it’s 1 do whatever and if its 2 do whatever
How do i make it kill any humanoid on the part after it picks one?
Ok I left out the humanoid because it’s something else but you would have to check if the humanoid touched the part then if it did set it’s health to zero or take away whatever health you can find this in other posts but I just covered picking the part
Sorry but i am quite new to scripting
You could put all the possible kill parts into a folder and use a for loop and math.random(1, (Number of kill parts)) like this:
local CollectionService = game:GetService("CollectionService")
CollectionServere:GetInstanceAddedSignal("KillPart"):Connect(function(Part)
Part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local humanoid = hit.Parent.Humanoid
humanoid.Health = 0
end
end)
end)
local function CreateKillParts()
local KillParts = math.random(1, 10) --10 is just an example number
for i,v in pairs(workspace.Folder:GetChildren()) do
if i == KillParts then
CollectionService:AddTag(v, "KillPart")
end
end
end
So this should work, it uses math.random and collection service to make stuff simple.
I am too so I don’t know everything but I have seen some posts like that
Ok well there you go my script doesn’t do the kill thing but it will pick a part
Just say CreateKillParts() to create new ones, but the old ones will not go away unless you use remove tag.
Oh ok thanks anyway I really appreciate it!
Wait when i ran the script it did not kill me on either of the parts do i have to edit the script?
Like instead of kill part i change it to what my parts are called?
You can use this:
local partList = {"Part1","Part2"}
local getPart = partList[math.radom(1,#partList)]
Character.HumanoidRootPart.CFrame = CFrame.new(workspace[getPart].Position.X, workspace[getPart].Position.Y +9, workspace[getPart].Position.Z)
Where do i put the script in the game because i dont know where to put it.
If you’re new to scripting, then I highly recommend you NOT to make this topic and go and learn basics of scriptings before you even ask because this is something you should know when learning the basics of it.
Really? Thanks for the advice but could you recommend me some channels to watch?
AlvinBlox, TheDevKing, and more. You cant just rely on one scripter’s style. You must learn from various scripters in order to script efficiently.
Peas factory is also great to learn from.