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

my localscript cant pick up OnClientEvent how to fix?

Asked by
ym5a 52
3 years ago
Edited 3 years ago
local function getPlayerFromCharacter(character)
    for _, player in pairs(game:GetService("Players"):GetPlayers()) do
        if player.Character == character then
            return player
        end
    end
end

function onTouched(part)
    if part.Parent:findFirstChild("Humanoid")~=nil then
        print("humanoid touched")
        local char = part.Parent:findFirstChild("Humanoid").Parent
        getPlayerFromCharacter(char)
        local player = getPlayerFromCharacter(char)
        local plrgui = player.PlayerGui:FindFirstChild("PlayerGui")
        game.ReplicatedStorage.RemoteEvent:FireClient(player)
        print("fired")
    end
end

script.Parent.Touched:connect(onTouched)

The script above succesfully prints everything it should once touched.

Although the LocalScript below me does nothing

game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function(player)
    print("received")
player.PlayerGui.bacteria.Enabled = true
local text = player.PlayerGui.bacteria.TextLabel.Text
text = "Y"
wait()
text = "Yo"
wait()
text = "You"
wait()
text = "You h"
wait()
text = "You ha"
wait()
text = "You hav"
wait()
text = "You have"
wait()
print("changed to you have")
end)

1 answer

Log in to vote
0
Answered by 3 years ago

I think you over-complicated yourself with another function of getplayerfromcharacter and a lot of stuff. I ll give u a example down below.

function onTouched(part)
    local player = game.Players:GetPlayersFromCharacter(part.Parent)
if player then
game.ReplicatedStorage.RemoteEvent:FireClient(player)
      end
    end

Ad

Answer this question