Cast error with remote events

I’m having an issue with calling events.
I have these lines of code.

local playername = humanoid.Parent.Name
	script.GUIStart:FireClient(playername)

It says, unable to cast to object. Please help, I am not very experienced in casting events.
If this has already been asked and solved, please direct me to the thread.
Thank you!

Slight thing with solution, I did not know FireAllClients and FireClient were different, so techincally post #2 is the solution, while I learned of my issue in post 16/17. Credit should go to both of these guys.

1 Like

should be

local player = game:GetService("Players"):GetPlayerFromCharacter(humanoid.Parent)
local playername = game:GetService("Players"):GetPlayerFromCharacter(humanoid.Parent).Name

script.GUIStart:FireClient(player,playername)

You need to fire the player argument not the name (not sure if u want to send it or use it as a player arg) If you don’t want to send the player name, just remove the playername variable from the firing function and the variable itself.

This fixes the issue, but then this happens. This is a GUI script.

game.Workspace.CORE.CORE.Script.GUIStart.OnClientEvent:Connect(function(player,playername)
	print("caught")
	print(script.Parent.Parent.Parent.Name)
	print(player.name)
	if script.Parent.Parent.Parent.Name == player.name then
		script.Parent.Enabled = true
	end
end)

Where is says print player.name, it comes up as nil. Why is this?

This is the portion of the server script used.

core.Touched:Connect(function(hit)
	print("burning")
	if hit.Name == "Handle" then
		 humanoid = hit.Parent.Parent.Humanoid
	else
		 humanoid = hit.Parent.Humanoid
	end
	print ("skin detcted")
	humanoid.Health = 0
	local player = game:GetService("Players"):GetPlayerFromCharacter(humanoid.Parent)
	local playername = game:GetService("Players"):GetPlayerFromCharacter(humanoid.Parent).Name

	script.GUIStart:FireClient(player,playername)
	
end)
1 Like
core.Touched:Connect(function(hit)
	print("burning")
	if hit.Name == "Handle" then
		 humanoid = hit.Parent.Parent.Humanoid
	else
		 humanoid = hit.Parent.Humanoid
	end
	print ("skin detcted")
	humanoid.Health = 0
	local player = game:GetService("Players"):GetPlayerFromCharacter(humanoid.Parent)
        print(player.Name)
	script.GUIStart:FireClient(player)
	
end)
game.Workspace.CORE.CORE.Script.GUIStart.OnClientEvent:Connect(function(player)
	print("caught")
	print(script.Parent.Parent.Parent.Name)
	print(player.Name)
        print(player)
	if script.Parent.Parent.Parent.Name == player.Name then
		script.Parent.Enabled = true
	end
end)

Try those, lets see what is it about… Does it print the player’s name in the Server? And does it print in the Client?

1 Like

1 Like

Okay, I don’t see your Humanoid variable anywhere tho. Also there is no line 13 in the Localscript you sent?

1 Like

No need to pass the player name as a seperate variable

core.Touched:Connect(function(hit)
	print("burning")
	if hit.Name == "Handle" then
		 humanoid = hit.Parent.Parent.Humanoid
	else
		 humanoid = hit.Parent.Humanoid
	end
	print ("skin detcted")
	humanoid.Health = 0
	local player = game:GetService("Players"):GetPlayerFromCharacter(humanoid.Parent)
	script.GUIStart:FireClient(player)
end)
game.Workspace.CORE.CORE.Script.GUIStart.OnClientEvent:Connect(function()
    local player = game.Players.LocalPlayer
	print("caught")
	print(script.Parent.Parent.Parent.Name)
	print(player.name)
	if script.Parent.Parent.Parent.Name == player.name then
		script.Parent.Enabled = true
	end
end)
1 Like

Depends if they want to use localplayer.

1 Like

Based on their provided scripts, localplayer would be the best option for them

Oh well true, didn’t take a closer look. I tried the script with my own version, worked… (mine version)
Seems like an other issue… OP may we see the upper part of the code?

Doesn’t work, your local script just compares name to name. Wouldn’t help.

Can you please tell me the exact error?

Sure.

local core = script.Parent
local humanoid

That’s serverside.
Localside is fully posted.

Alright, it seems like the name is nil aka the player. Could you please show us the upper part of the code?

I didn’t test it, I can just see it won’t work. Take a good look at it. (The localscript you posted.)

This is in a local script right? There isn’t much point checking if the player is the player…
just remove that section:

game.Workspace.CORE.CORE.Script.GUIStart.OnClientEvent:Connect(function()
    local player = game.Players.LocalPlayer
	print("caught")
	print(script.Parent.Parent.Parent.Name)
	print(player.name)
    script.Parent.Enabled = true
end)

I’ve showed the upperpart of everything/.

You’re kidding right…?

Test the code that has been provided instead of dismissing it. You are having issues with the remote events, and I have experience using remote events. I reckon that I probably know what would work and what wouldn’t

Wait, when a client event is fired, do all local scripts capture it? This GUI is inside the player, so would all those GUI scripts capture it? Or only the one being fired to the player?

Yeah good point. I"ll test it anyway.