#how do i make it only select one string option when the part is touched

1 messages · Page 1 of 1 (latest)

hidden geode
#

basically as the title suggest! i was hoping to figure out how to make it so that it picks a different string option when touched and wait 3 seconds until it changes again instead of phasing through all of them as it is at the moment. I attempted placing wait functions in different areas to see if that helped but it ultimately did nothing

vast torrent
# hidden geode my scripts

Alright, so there's a few things wrong with this. Currently, it's firing every single time a part of the character touches and untouches it, which is a lot. So, the wait won't do crap.

What you need to do is make it log the players touching it in a table. To make life easier and not have it trigger every time each segment of the arms, torso, legs etc. touch the part as well, you should also make it check that otherPart is the HumanoidRootPart.

Now, for the delay of 3 seconds that you want for it to cycle through texts while the player is touching it, you could just spawn a function that repeats the text swap every 3 seconds unless the player is no longer touching.

The script for this would look similar to:

local Players = game:GetService("Players")
local wall = script.Parent
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local touchingPlayers = {}

wall.Touched:Connect(function(otherPart)
  if otherPart.Name ~= "HumanoidRootPart" or table.find(touchingPlayers, otherPart.Parent) then return end

  local player = Players:GetPlayerFromCharacter(otherPart.Parent)
  if not player then return end
  
  table.insert(touchingPlayers, otherPart.Parent)
  
  ReplicatedStorage.TouchWater:FireClient(player, true)

  task.spawn(function()
    while task.wait(3) do
      if not table.find(touchingPlayers, otherPart.Parent) then break end
      ReplicatedStorage.TouchWater:FireClient(player, true)
    end
  end)
end)

wall.TouchEnded:Connect(function(otherPart)
  if otherPart.Name ~= "HumanoidRootPart" then return end

  local find = table.find(touchingPlayers, otherPart.Parent)
  local player = Players:GetPlayerFromCharacter(otherPart.Parent)

  if find and player then
    table.remove(touchingPlayers, find)
    ReplicatedStorage.TouchWater:FireClient(player, false)
  end

end)
#

I didn't write this in studio so there might be a couple typos

hidden geode
#

the only issue now rlly is that the hint doesnt go away anymore but i have to look into it more

vast torrent