Chat service help

robloxapp-20211016-1216281.wmv (1.3 MB)
I am trying to use the Chat Service for my game but I keep getting this issue. ^^^^ (video explains) When I touch the ball I just want it to say it once and then if I stop touching it but touch it again it says it again but still, only once. Not spam. Here’ss my code.

local chat = game:GetService("Chat")

script.Parent.Touched:Connect(function(hit)
	chat:Chat(hit.Parent.Head, "whats this.. ball thing?", Enum.ChatColor.White)
end)

I’d really be thankful if somebody could support me with this situation.

Add a Debounce.

alright gimme a sec i’ll code it in and tell you results after

problem. it wont even say anything when i touch and i have an error at end)

local chat = game:GetService("Chat")
local RESET_SECONDS = 1
local isTouched = false

script.Parent.Touched:Connect(function(hit)
	if not isTouched then  -- Check that debounce variable is not true
		isTouched = true  -- Set variable to true
		chat:Chat(hit.Parent.Head, "why is this.. ball here?", Enum.ChatColor.White)
		wait(RESET_SECONDS)  -- Wait for reset time duration
		isTouched = false 
end)

Im not the best programmer, but this works:

local chat = game:GetService("Chat")

script.Parent.Touched:Connect(function(hit)
	chat:Chat(hit.Parent.Head, "whats this.. ball thing?", Enum.ChatColor.White)
script.Disabled = true
end)

DOn’t know what you’re doing.

Try this:

local chat = game:GetService("Chat")
local RESET_SECONDS = 1
local isTouched = false

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then 
         print("Player is touching part.")
        if isTouched == false then  -- Check that debounce variable is not true
		    isTouched = true  -- Set variable to true
		    chat:Chat(hit.Parent.Head, "why is this.. ball here?", Enum.ChatColor.White)
		    wait(RESET_SECONDS)  -- Wait for reset time duration
		    isTouched = false 
        end
    end
end)

(After I got the solution, I just wanted to state that you didn’t check if a Player (humanoid) touched it.)

Hope this helps a lil!

1 Like

Thanks I’ve never used Debounce so I was confused

1 Like

What do you mean? I’m confused. It says

if hit.Parent:FindFirstChild("Humanoid") then

In my variant I made it so it checks for a player. In your variant of the script you just immediately try and execute your code without any proper checks.