Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

touched and touchended functions are not working?

Asked by
RiotGUI 15
6 years ago
Edited 6 years ago

I attempted to make a part that only one player can touch and be added to a table, and when he untouches the part he gets removed from that table.

But my code didn’t work and I don’t know the reason

Here’s my attempt:

01local team1 = script.Parent.Team1
02 
03local maximum_1 = false
04 
05local team_table_1 = {}
06 
07   
08 
09local function onTouch(hit)
10 
11local player = game.Players:GetPlayerFromCharacter(hit.Parent)
12 
13if not player then return end
14 
15if not maximum_1 then
16 
17maximum_1 = true
18 
19while true do
20 
21wait(hit)
22 
23table.insert(team_table_1, player.Name)
24 
25print'added'
26 
27end
28 
29end
30 
31end
32 
33local function onTouchEnded()
34 
35table.remove(team_table_1, 1)
36 
37print'removed'
38 
39end
40 
41team1.Part1.Touched:Connect(onTouch)
42 
43team1.Part1.TouchEnded:Connect(onTouchEnded)

1 answer

Log in to vote
0
Answered by 6 years ago

:Remove is deprecated and even using :Destroy you are only removing the element so it cant be detected again. What I would do is parent it in replicated storage then a wait() method and then add it back so it can detect it. Computers need time to think!

0
Sorry but I don't understand, what should I do exactly? Can you explain and give an example in a sample of code? RiotGUI 15 — 6y
0
Don't remove the table. Just set it to a new parent outside of the global scene. Table isnt a element. It is a method so you can store it as a variable which we call values. You can make a stringvalue then parent the string value to the replicated storage. ClockWallie 28 — 6y
Ad

Answer this question