Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is my script that's meant to print a message when a MeshPart touches it not working?

Asked by 5 years ago

Hello, I've been working on this script for a few days now, but it's not working. This script is meant to print a message if a MeshPart is hitting the Part.

Here's a picture of when this is meant to happen: Here

script.Parent.Touched:Connect(function(hit)
    local h = hit
    if (h ~= nil) then
        if h:IsA("MeshPart") then
            print(h.Name.."hit me!")
            game.ReplicatedStorage:WaitForChild("vals"):WaitForChild("Winner").Value = h.Name
            script.Parent:Destroy()
        end
    end
end)

Any help would be appreciated. Thanks in advance!

0
Why do you have parenthesis around the argument on line 3 sheepposu 561 — 5y
0
idk if Lua accepts that syntax, but you could be getting an error from it which would explain why it doesn't print anything sheepposu 561 — 5y

2 answers

Log in to vote
0
Answered by
WoTrox 345 Moderation Voter
5 years ago
script.Parent.Touched:Connect(function(hit)
        if hit.Parent:IsA("MeshPart") then
            print(hit.Parent.Name.."hit me!") --If not working try use hit.Parent only
            game.ReplicatedStorage:WaitForChild("vals"):WaitForChild("Winner").Value = hit.Parent.Name --Here too
            script.Parent:Destroy()
        end
end)

I hope this will work

0
OK thank you! I'll try now! ProvingTrottle 27 — 5y
0
For some reason this doesn't work. I've done every thing you said. ProvingTrottle 27 — 5y
0
Error code? WoTrox 345 — 5y
0
none ProvingTrottle 27 — 5y
View all comments (2 more)
0
Hmm... WoTrox 345 — 5y
0
The WaitForChild can make an error like this. If the vals doesn't exists then the script waits until it appears inside the ReplicatedStorage. WoTrox 345 — 5y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Sooo, I solved this myself, because apparently if you turn Anchored on, it won't detect the part, even with CanCollide on!

Answer this question