✓ Accepted answer
Let's insert all the BaseParts of the model named "Sand" in a table. I'll use a loop for that:
Sand = game.Workspace:WaitForChild("Sand")
local TouchableParts = {}
local tableposition = 1
for i, v in pairs (Sand:GetChildren()) do
if v:IsA("BasePart") then
table.insert(TouchableParts, tableposition, v)
tableposition = tableposition + 1
end
end
Now, let's make a loop of the objects in "TouchableParts" and detect when the part is touched.
Sand = game.Workspace:WaitForChild("Sand")
local TouchableParts = {}
local tableposition = 1
for i, v in pairs (Sand:GetChildren()) do
if v:IsA("BasePart") then
table.insert(TouchableParts, tableposition, v)
tableposition = tableposition + 1
end
wait()
end
for i, v in pairs (TouchableParts) do
v:Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
end
end)
end
This may seems a bit long, but it's the fastest version I've made. Hope this helped!
26 comments
change findfirstchild to waitforchild
okay but now it says connect is not a valid member of model..
is this script called gravity controller or is it a different script
a model cannot use the Touched function
oh yes. is there a part inside sand?
gravity controller is a different script
ok. is gravity controller inside of this script. meaning is this script the parent of it?
if there's a part, use loops
no its not inside of this script
message me on discord if you have it GamerLoIiaz#4197
when you say script.gravitycontroller it is seeing this script as a parent. where is you gravitycontroller script?
ReplicationStorage
ok. do this. instead of script.gravitycontroller:destroy you want to do game.ReplicatedStorage.GravityController:Destroy()
I hope that works
It is saying GravityController is not a valid member of ReplicatedStorage..
wait you can do this
what is in your replicated storage? say it like this: Replicated Storage -- Item1, Item2
and use capitals
Item1 DrawClass Script, Item2 GravityController, Item3 Event, Item4 Event
Are you moving the script to another location when the game starts?
no
Hmm. This is odd. Can you allow me to configure your game? I wont mess with anything or copy anything.
yes
Ok.
add me so I can invite you to team build
done