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

how can i make it so when i touch a brick it plays event only one time?

here is teh script



Debounce = false
function onTouched(Hit)
    local Player = Hit.Parent and Hit.Parent:FindFirstChild("Humanoid") and Hit.Parent.Humanoid.Health > 0 and game.Players:GetPlayerFromCharacter(Hit.Parent)
    if Player then
	  local plr = game.Workspace:FindFirstChild(Player.Name)
   game:GetService("Chat"):Chat(script.Parent.Head, "Somethings Wrong. HMM", Enum.ChatColor.Blue)
wait(4)
   game:GetService("Chat"):Chat(script.Parent.Head, "OH I NOW KNOW, ITS THE PART UPDATE *i don wanna get banned* so ill make him look even better", Enum.ChatColor.Blue)
wait(5)
game.Workspace.Stan.FakeShirt.Transparency = 1
game.Workspace.Stan.fakeleg.Transparency = 1
game:GetService("Chat"):Chat(script.Parent.Head, "You Are getting banned today", Enum.ChatColor.Blue)
game.StarterGui.BAN.Frame.Visible = true
game.Workspace.Stan.FakeShirt.Transparency = 0
game.Workspace.Stan.fakeleg.Transparency = 0
    end
end

script.Parent.Touched:connect(onTouched)

everytime i take a step or move, the script playes again and goes back to the start alot lets say i touch it, the script looks when i touch it, is there a way to make it play everytime when a new humaniod touches it once it plays. or something like that

1 comment

0

i think you should try debounce. changing the value of it when Touched() happens

1 answer

using a Variable, like this:

local Touched = false

function onTouched()
	if Touched == false then
		Touched = true
		--Rest of the Code Below...
	end
end

script.Parent.Touched:Connect(onTouched)

1 comment

0

thats called a debounce and it isnt a complete solution

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