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
5 years ago
Edited 5 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:

local team1 = script.Parent.Team1

local maximum_1 = false

local team_table_1 = {}



local function onTouch(hit)

local player = game.Players:GetPlayerFromCharacter(hit.Parent)

if not player then return end

if not maximum_1 then

maximum_1 = true

while true do

wait(hit)

table.insert(team_table_1, player.Name)

print'added'

end

end

end

local function onTouchEnded()

table.remove(team_table_1, 1)

print'removed'

end

team1.Part1.Touched:Connect(onTouch)

team1.Part1.TouchEnded:Connect(onTouchEnded)

1 answer

Log in to vote
0
Answered by 5 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 — 5y
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 — 5y
Ad

Answer this question