How i can cast value to object in remote event


I am making select player and then you can sync animation with same track of selected player
and if you click on unsync you unsync with that player
there was only 1 error when i click on sync its show error
image

local Players = game:GetService("Players")
local Player = game.Players.LocalPlayer;
script.Parent.Frame.Unsycn.MouseButton1Click:Connect(function()
	game.ReplicatedStorage.SyncDance:InvokeServer(nil)
	script.Parent.Enabled = false
	print("fire = nil")
end)

script.Parent.Frame.Sycn.MouseButton1Click:connect(function()
	local target = script.Parent.Frame.tplr.Text
	local victim = game.Players:GetPlayerFromCharacter(target)
	if victim then
		game.ReplicatedStorage.SyncDance:InvokeServer(victim)
	else
		print("error")
	end
	script.Parent.Enabled = false
	print("fire = "..target)
end)

image

You could fire server using the player’s UserId using victim.UserId and get the player by using game.Players:GetPlayerByUserId(thePassedVariable) in the server.

i am going to try it now

:shushing_face:
:happy2:

The problem is here.

target is a string, but GetPlayerFromCharacter expects a player’s character, which is a model.

Assign game.Players:FindFirstChild(target) instead.

By the way, you don’t have to use the UserId or something.

You still can?

chararardsrklsd

Yes, but it is not the best way of doing it. It has to access Roblox APIs which can take a few seconds.

Edit: Perhaps it does some optimizations when the player is in the server? Still doesn’t change the fact that just passing the player is better.

Hmmm ok thank you for sharing that, I had no clue.

its showing error
image

image

Do this:

local victim = Players:FindFirstChild(target)
2 Likes

thenk you Cnr123451 its worked
:grinning: :grinning: :grinning: :grinning:

1 Like