Expected Instance, But got string on line 6

I made this script, however, it kept having errors.

local ReplicatedStorage = game.ReplicatedStorage
local JobIdRemoteEvent = ReplicatedStorage:WaitForChild("JobIdRecieved")

JobIdRemoteEvent.OnServerEvent:Connect(function(PreviousJobID, Player)
	local PlayerPersonalJobIDValue = Instance.new("NumberValue")
	PlayerPersonalJobIDValue.Parent = Player
	PlayerPersonalJobIDValue.Value = PreviousJobID
	PlayerPersonalJobIDValue.Name = "MyPersonalJobID"
end)

This is a server script. The script firing is a local script and will be shown below

wait()
local TeleportService = game:GetService("TeleportService")
local teleportData = TeleportService:GetLocalPlayerTeleportData()

local ReplicatedStorage = game.ReplicatedStorage
local JobIdRemoteEvent = ReplicatedStorage:WaitForChild("JobIdRecieved")

local Player1 = game.Players.LocalPlayer
local PreviousServerJobID = teleportData.Data1

JobIdRemoteEvent:FireServer(PreviousServerJobID, Player1)



Is there anything wrong with my code above. Sorry for bad english I m bad at the language

my bad i read it wrong

:FireServer(PrevID, Player1)

Passes along those arguments and when a client fires the server the first argument is always the player so Player1 is meaningless

1 Like

Well, you don’t need to pass the player, it’s automatically passed.

local ReplicatedStorage = game.ReplicatedStorage
local JobIdRemoteEvent = ReplicatedStorage:WaitForChild("JobIdRecieved")

JobIdRemoteEvent.OnServerEvent:Connect(function(Player, PreviousJobID)
	local PlayerPersonalJobIDValue = Instance.new("NumberValue")
	PlayerPersonalJobIDValue.Parent = Player
	PlayerPersonalJobIDValue.Value = PreviousJobID
	PlayerPersonalJobIDValue.Name = "MyPersonalJobID"
end)
wait()
local TeleportService = game:GetService("TeleportService")
local teleportData = TeleportService:GetLocalPlayerTeleportData()

local ReplicatedStorage = game.ReplicatedStorage
local JobIdRemoteEvent = ReplicatedStorage:WaitForChild("JobIdRecieved")

local Player1 = game.Players.LocalPlayer
local PreviousServerJobID = teleportData.Data1

JobIdRemoteEvent:FireServer(PreviousServerJobID)

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