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

.touched is not fireing when I touch the part?

-- ORGINAL FIRST SCRIPT
for i = 120,0,-1 do
        status.Value = "Game In Progress:"..i
if game.ReplicatedStorage.Finished.Value == "yes" then
i=0		
end

-- ORIGINAL SECOND SCRIPT
script.parent.Touched:connect(function()
	local Fin = game.ReplicatedStorage.Finished 
	Fin.Value = "yes"
end)


-- FIXED FIRST SCRIPT
script.Parent.Touched:Connect(function(HIT)
	if HIT.Parent:FindFirstChild("Humanoid") then
	local Fin = game.ReplicatedStorage.Finished 
	Fin.Value = "yes"
	print("ixgottouvhed")	
	end
end)




-- FIXED SECOND SCRIPT 

for i = 120,0,-1 do
        status.Value = "Game In Progress:"..i
 wait(1)
if game.ReplicatedStorage.Finished.Value == "yes" then break end
end

The first script is an excerpt from a larger script. It basically keeps track of the round time, and the round automatically ends if the string value "Finished" is yes.

The other script is under a part that when touched, makes the string value "Finished"

Why does nothing happen when i touch the part the second script is under?

EDIT: I got the problem fixed, but here's the code for any one who has this problem in the future.

Thanks to all that helped.

1 comment

1

You forgot to uppercase the 'P' in 'Parent' on line 1. XP

2 answers

✓ Accepted answer
-- ORGINAL FIRST SCRIPT
for i = 120,0,-1 do
        status.Value = "Game In Progress:"..i
if game.ReplicatedStorage.Finished.Value == "yes" then
i = 0     
end

-- ORIGINAL SECOND SCRIPT
script.parent.Touched:connect(function()
    local Fin = game.ReplicatedStorage.Finished 
    Fin.Value = "yes"
end)


-- FIXED FIRST SCRIPT
script.Parent.Touched:Connect(function(HIT)
    if HIT.Parent:FindFirstChild("Humanoid") then
    local Fin = game.ReplicatedStorage.Finished 
    Fin.Value = "yes"
    print("ixgottouvhed")   
    end
end)




-- FIXED SECOND SCRIPT 

for i = 120,0,-1 do
        status.Value = "Game In Progress:"..i
 wait(1)
if game:GetService("ReplicatedStorage"):WaitForChild("Finished").Value == "yes" then break end
end

1 comment

0

I'll accelt you for being clever lol

First - check if the thing it's touching is actually a player(also capitalize Parent, just because it looks nicer).

function touched(yasure)
-- yasure is what it hit btw

if yasure.Parent:findFirstChild("Humanoid") then
-- set the value
end
end

script.Parent.Touched:connect(touched)

For all we know, it might be activating before someone actually touches it.

3 comments

0

:Connect.

0

LOL, programical partly solved my problem. Now it actually fires the function. I was going add the code to check if it was a humanoid later. Now the only problem is the timer for the game doesn't go to 0

0

Ok, if a person touches a brick, the round doesn't end, but once the next round comes by, it ends instantly.

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