Finding a Player through an ObjectValue

I have an ability in my game that puts a player into a “stasis”
The stasis can be broken by certain characters

The issue I have is that I’m using an ObjectValue, and the Value is the player but when I try to use :FireClient(target) it says it’s not a player…
image

Here’s my script

local event = game.ReplicatedStorage:WaitForChild("Events"):WaitForChild("StasisBreak")

script.Parent.Triggered:Connect(function(player)
	local target = game.Players:FindFirstChild(script.Parent.Parent.StasisPlayer.Value)
	if player.Character:FindFirstChild("Warlock") and player.Name ~= target then
		local anim = player.Character.Humanoid:LoadAnimation(game:GetService("ServerStorage"):WaitForChild("Animations"):WaitForChild("BreakStasis"))
		anim:Play()
		wait(4.5)
		event:FireClient(target) -- it errors here
	end
end)

the error i get
image

I still get the same error if I remove the target variable and do :FireClient(game.Players:FindFirstChild(script.Parent.Parent.StasisPlayer.Value)) instead…

1 Like

Could you add some prints before the if statement and right before you call FireClient displaying target and target’s type. Looking at your if statement you are comparing player.Nam` to target so both should be strings if it passes the if statement but FindFirstChild returns Instance? so we need a little more information.

1 Like

You can’t use :FindFirstChild on an object, only on its name. So, you do
game:GetService("Players"):FindFirstChild(script.Parent.Parent.StasisPlayer.Value.Name)
FindFirstChild will return nil if it doesn’t find anything, which is what caused your error.

1 Like

This fired it to the server, thank you!!

However it also made an error show up that didn’t show up before.

this is the script it errored from

local event = game:GetService("ReplicatedStorage"):WaitForChild("Events"):WaitForChild("StasisBreak")

event.OnServerEvent:Connect(function(target, brk)
	if brk == "StasisBreak" then
		if game.Workspace:FindFirstChild(target.Name.."Stasis") then -- here
			local stasis = game.Workspace:FindFirstChild(target.Name.."Stasis")
			stasis:Destroy()
			for _,anims in pairs(target.Character.Humanoid:GetPlayingAnimationTracks()) do
				if anims.Name == "Stasis" then
					anims:Stop()
				end
			end
			target.Character.Humanoid.WalkSpeed = 16
		end
	end
end)

It also shows the same error if i do (target.."Stasis")

You need to do target.Name, as target is an instance.

charscharschars

I did, and it came up with the error as well.

Are you sure? I really don’t know then, as target.Name is still a string. Is it a different error? Is it on a different line?

Nope, it’s all on the one line i marked with -- here

Yeah, sorry. No idea what’s causing it. Could be an engine bug? Try restarting studio or your device.

nevermind, when i tested it with just target.."Stasis" i forgot to change the first part of it so it was still searching for target.Name.."Stasis" but then the second part where it destroys it, it was looking for target.."Stasis", so it was causing an error there.

it works perfectly now, thank you so much!!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.