Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

(DESPERATE) For some reason in the output it is saying Touched is not a member of workspace?

Sand = game.Workspace:FindFirstChild("Sand")

Sand.Touched:Connect(function(hit)
    local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
    if player then
	script.GravityController:Destroy()
    end
end)

I just want it to detect if the player touches the part sand and if it does detect that a player touches it then it will destroy the Gravity Controller script. Thats all I want.

If you would like to help me message me on discord GamerLoIiaz#4197

26 comments

0

change findfirstchild to waitforchild

0

okay but now it says connect is not a valid member of model..

0

is this script called gravity controller or is it a different script

0

a model cannot use the Touched function

0

oh yes. is there a part inside sand?

0

gravity controller is a different script

0

ok. is gravity controller inside of this script. meaning is this script the parent of it?

0

if there's a part, use loops

0

no its not inside of this script

0

message me on discord if you have it GamerLoIiaz#4197

0

when you say script.gravitycontroller it is seeing this script as a parent. where is you gravitycontroller script?

0

ReplicationStorage

0

ok. do this. instead of script.gravitycontroller:destroy you want to do game.ReplicatedStorage.GravityController:Destroy()

0

I hope that works

0

It is saying GravityController is not a valid member of ReplicatedStorage..

0

wait you can do this

0

what is in your replicated storage? say it like this: Replicated Storage -- Item1, Item2

0

and use capitals

0

Item1 DrawClass Script, Item2 GravityController, Item3 Event, Item4 Event

0

Are you moving the script to another location when the game starts?

0

no

0

Hmm. This is odd. Can you allow me to configure your game? I wont mess with anything or copy anything.

0

yes

0

Ok.

0

add me so I can invite you to team build

0

done

1 answer

✓ 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
			--destroy the gravity controller here, idk where you put your gravitycontroller thing so I didn't write the line which the script destroys the gravitycontroller, it's up to you to put it here
		end
	end)
end

This may seems a bit long, but it's the fastest version I've made. Hope this helped!

1 comment

0

When I add the destroy line it says Expected '(', '{' or got, ':' on line 14

This discussion is preserved as it was. New answers, comments, and votes are closed.