iQeeDEVS
(iQeeDEVS)
March 28, 2024, 4:52pm
#1
I want pass NPC’s position to Client from Workspace.
But it always says Unable to cast value to Object or if i try pass only NPC instead cframe it says it should be player object.
I want to pass the position. Can someone help?
script.Parent.ProximityPrompt.Triggered:Connect(function(player)
local npc = script.Parent.Parent:WaitForChild("NPC").HumanoidRootPart.CFrame
RS.StartGame:FireClient(player)
RS.FitChar:FireClient(npc)
end)
East98
(East98)
March 28, 2024, 6:17pm
#2
When using the RemoteEvent:FireClient
method, the first argument needs to be a Player
. This line does not do that:
RS.FitChar:FireClient(npc)
You can still pass the npc
, but you have to specify which Player
you want to send the event to like this:
RS.FitChar:FireClient(player, npc)
If you want to send it to all players, then you can use RemoteEvent:FireAllClients
.
1 Like
Hot_Coder
(Poshinky)
March 28, 2024, 6:20pm
#3
You have 2 Issues In Your Code!
First: You are not Passing the Player inside of :FireClient() It Should Be :FireClient(player, npc)
Second: This is a Very Bad Practice Because if the NPC is not loaded in player Radius For Example if You Have Streaming Enabled On Its gonna be Nil on the Client.
iQeeDEVS
(iQeeDEVS)
March 28, 2024, 6:20pm
#4
Thank you, it worked but can you tell me why it printed position like that:
-422.252014, 0, -661.062988, 0, 0, -1, 0, 1, 0, 1, 0, 0 - Client - LocalScript:17
Isn’t it like x,x,x? that is other numbers. i just want to get position.
iQeeDEVS
(iQeeDEVS)
March 28, 2024, 6:21pm
#6
Oh… i am garbage for scripting.
Blizzero
(Blizzero)
March 28, 2024, 6:25pm
#7
This would be true if the RemoteEvent was passing the NPC Instance/model; however, it is instead passing its CFrame. Even if the NPC does not exist on the client, the client can still receive this CFrame just fine.
iQeeDEVS
(iQeeDEVS)
March 28, 2024, 6:26pm
#8
the script works just when player interact to E on npc
Hot_Coder
(Poshinky)
March 28, 2024, 6:30pm
#9
OH It looks like i didn’t read the Post well Thanks For Clearing That out!
system
(system)
Closed
April 11, 2024, 6:30pm
#10
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.