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

chat message system getting the name of the accesory and not the name of the player?

Asked by 2 years ago
Edited 2 years ago

Im making a chat system when the player touched the end part, it ussually get the name of the accesory and not the parent of it, how can i fix this?

the script in the end part

script.Parent.Touched:Connect(function(plr)
game.ReplicatedStorage.ReachedEnd:FireAllClients(plr.Parent.Name)
end)

the script that makes the chats

game.ReplicatedStorage.ReachedEnd.OnClientEvent:Connect(function(plrName)

game.StarterGui:SetCore("ChatMakeSystemMessage", {
        Text = plrName .. " Reached the end",
        Color = Color3.fromRGB(255, 255, 255),
        Font = Enum.Font.Cartoon,
        TextSize = 18,
    })
end)

2 answers

Log in to vote
0
Answered by 2 years ago

Well, you see, Touched event returns a part, not a player instance, therefore, change the script in the end part to something like this:

script.Parent.Touched:Connect(function(part)
    for i,v in pairs(game.Players:GetPlayers()) do
        if part:IsDescendantOf(v.Character) then
            game.ReplicatedStorage.ReachedEnd:FireAllClients(v.Name)
        end
    end
end)

ur lucky that i'm online rn, this question is literally less than 5 minutes old and there's already an answer

Ad
Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

Well, seems like your script is correct but what got touched is the part of the accessory so you can do

script.Parent.Touched:Connect(function(hit)
if hit.Parent.Parent:FindFirstChild('Humanoid') then


game.ReplicatedStorage.ReachedEnd:FireAllClients(hit.Parent.Parent.Name)

elseif hit.Parent:FindFirstChild('Humanoid') then


game.ReplicatedStorage.ReachedEnd:FireAllClients(hit.Parent.Name)

end
end)

Answer this question