What do you want to achieve?
I’d like to be able to pass the player to the remote event fire call
What is the issue?
I cannot pass the player as an argument in the event fire call.
What solutions have you tried so far?
I’ve tried using:
local human = player:GetPlayerFromCharacter(base.Parent)
print(human.Name)
Code for brick that is touched (NORMAL SCRIPT)
local part = script.Parent
local remoteEvent = game.ReplicatedStorage.loader1
local player = game:GetService("Players")
part.Touched:Connect(function(base)
local human = player:GetPlayerFromCharacter(base.Parent)
print(human.Name)
--remoteEvent:FireClient(human)
end)
Code for GUI event/onFireEvent event (LOCAL SCRIPT)
local remoteEvent = game.ReplicatedStorage.loader1
local frame = script.Parent
local tweenService = game:GetService("TweenService")
remoteEvent.OnClientEvent:Connect(function()
local targetPos = UDim2.new(0.158, 0, 0.784, 0)
local info = TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut)
local tween = tweenService:Create(
frame,
info,
{Position = targetPos}
)
end)
I get the error that “human” isn’t a player but the code says otherwise, I’m quite confused and have no clue what to do.
part.Touched:Connect(function(base)
if base.Parent:FindFirstChild("Humanoid") then
local human = game.Players:FindFirstChild(base.Parent.Name)
end
end)
local part = script.Parent
local remoteEvent = game.ReplicatedStorage.loader1
local player = game:GetService("Players")
part.Touched:Connect(function(base)
local human = player:GetPlayerFromCharacter(base.Parent)
if human then -- human should be nil if GetPlayerFrom....() doesn't obtain a Player so code proceeds
print(human.Name)
--remoteEvent:FireClient(human)
end
end)
add a check to see if it is a player or not
such as
local part = script.Parent
local remoteEvent = game.ReplicatedStorage.loader1
local players = game:GetService("Players")
part.Touched:Connect(function(otherPart)
local char = otherPart.Parent
local humanoid = char:FindFirstChildOfClass("Humanoid")
if char and humanoid then
local player = players:GetPlayerFromCharacter(char)
if player then
print(player.Name)
--whatever else you wanna do
end
end
end)
local part = script.Parent
local remoteEvent = game.ReplicatedStorage.loader1
local player = game:GetService("Players")
part.Touched:Connect(function(base)
local human = base.Parent:FindFirstChild("Humanoid") or base.Parent.Parent:FindFirstChild("Humanoid"
if human then
local player = player:GetPlayerFromCharacter(human.Parent)
remoteEvent:FireClient(player)
end
end)