Thanks in advance for the help!
-
What do you want to achieve?
I want to create a script (or scripts for that matter) that facilitate interaction between parts. Essentially, most of my parts (I call them cells) have a value (cellValue). If part a hits part b, and part a’s value is greater, I delete part b and give the owner of part a points. I can handle all of the specifics on my own, but I seek advice on how to do this in the best way. -
What solutions have you tried so far?
Currently, each part has a script:
local cell = script.Parent
local value = cell.cellValue
local Players = game:GetService("Players")
local name = cell.Parent.Name
local player = Players:FindFirstChild(name)
local cells = script.Parent.Parent
cell.Touched:Connect (function(part)
-- Filter any instances of the cell coming in contact with its players other cells
if part:IsDescendantOf(cells) then return end
--do stuff
if part.cellValue then
if part.cellValue > value then
local oPlayer = part.Parent.Parent
local points = oPlayer.leaderstats.points
points = points + cell.cellValue
cell:Destroy()
end
if part.cellValue == value then
local oPlayer = part.Parent.Parent
local points = oPlayer.leaderstats.points
local playerpoints = player.leaderstats.points
points = points + cell.cellValue
playerpoints = playerpoints + part.cellValue
cell:Destroy()
part:Destroy()
end
if part. cellValue < value then
local playerpoints = player.leaderstats.points
playerpoints = playerpoints + part.cellValue
part:Destroy()
end
end
end)
I look at it this way:
One player can have a lot of cells (I’m setting the max around 40). If there are 20 players, that means 80 interaction scripts floating around.
Questions:
Is this the best way of going about this?
Or is there another way of doing this?
Thanks everyone,
Someperson576