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

my localscript cant pick up OnClientEvent how to fix?

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

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

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