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

Tool on touch parenting service?

Asked by 5 years ago

Alright so i have an issue. I have a baseball that when thrown will become a child of the workspace. What I want to do is when the baseball is a homerun, it will trigger a message with the person who hit it. I have all of that done except the part with the players name. I don't know how to get the players name who hit it because the parent of the baseball is the workspace.

debounce = false

function onTouched(hit)
local player = --this is where i need help
if hit.Name == "Ball" and debounce == false then
debounce = true
local h = Instance.new("Message")
h.Parent = hit.Parent
h.Text = "Home run hit by"..player.Name
wait(4)
h.Parent = game.Workspace
h:remove()
debounce = false
end
end

script.Parent.Touched:Connect(onTouched)

1 answer

Log in to vote
0
Answered by
brok4d 77
5 years ago

NAME_PLAYER the name of the player

for i, child in pairs(game.Workspace:GetChildren())
    if child:IsA("Model") and child.Name == "NAME_PLAYER"  then

    end
end
0
This isn't want i meant, if I could easily name the player localplayer but that when the message would appear, it would name yourself not the player who hit the hr. Neon_isHere 100 — 5y
Ad

Answer this question