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

most hard question. unsolved problem about touch event please help!?

Script

local part = script.Parent

part.Touched:Connect(fuction() print("touched") end)

part.TouchedEndded:Connect(fuction() print("touched removed") end)

if i touched the block it spam both for some reason.i want is if i touch the block it print"touched" once, until the player get off the block and touch it again.i want is like voting map if you get in the block it +1 the value once, if you get off the block it -1 once. Thank you For Reading!

2 comments

0

you typo'd function

0

I edited my whole answer, check it out lol

2 answers

✓ Accepted answer

Hey there, I changed my script. That's because the script doesn't work. I've thought of a better idea.

Do 2 parts, a part was a normal platform, let name it part1; another part is longer than the part1, it's the same size, but it just longer, lets name it part2. The part2 was as above at the part1, make it invisible and able to through, also, anchor the part2. By the way, parent the script to the part2. Idea inspired by this youtube video.

Later, enter this script:

local part2 = workspace.part2

function OnTouching()
	print("touching")
	if part2.TouchedEnded:Connect(function()
		print("no touching")
	end
end)

part2.Touched:Connect(OnTouching)

This might work. That works like this, if you're not touching, you'll not printing no touching. However, you touched the part, prints touching, and left the part. They'll print no touching.

Remember this idiom I created myself: "Always try to through the lasers, why don't use a hammer and cheat to the end?" We have a lot of possibilities to think, it's not the hardest question, it's was just has a problem that we can't figure out. If we can't do straightway, let just turn in another way.

So, if there doesn't work again, or you don't know what do I mean, comment below, I'll think another way to fix this up.

4 comments

0

P.S. If there also wrong, tell me below here! I'll check it out, and I happy to help you ;)

0

thats not working ;-;

0

ahhh

0

Try to remove wait(1)?

your best bet is this

local part = script.Parent 
local touched= false -- we're going to use this to prevent spamming

part.Touched:Connect(function()
if touched == false then
touched = true -- this stops it from spamming
print("touched)
-- wait (1) remove the "--" and this text if it's still spammy
end)

part.TouchedEnded:Connect(function()
if touched == true then
touched = false
print("touched ended")
-- wait (1) remove the "--" and this text if it's still spammy
end)

You could even throw a wait in there to make sure you can't spam it by being slightly on it and slightly off of it.

Try that script and tell me how it goes.

2 comments

0

it still spam :C why no one can figure it out...

0

Line 7, touched was wrong that have a bad arguement #1. There have nothing localed with "touched. Counts nil.

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