I’m trying to make a marker that only appears for the player that imported the crate. I try to accomplish this by using a remote event, but when I fire the remote event from the server, the client says that the crate is nil?
ServerScript:
game.ReplicatedStorage.Events.Import.OnServerEvent:Connect(function(Player, Brick, Cost)
if Player.leaderstats.Money.Value >= Cost then
Player.leaderstats.Money.Value -= Cost
game.ReplicatedStorage.Events.Import:FireClient(Player, "You have successfully purchased, '"..Brick.Name.."' for "..Cost.."$"..", 300 seconds until it arives.")
task.wait(3) -- make this 300
local Crate = game:GetService("ReplicatedStorage").Crate:Clone()
Crate.Parent = workspace.CrateCache
Crate:WaitForChild("Material").Value = Brick
Crate:WaitForChild("Owner").Value = Player
game.ReplicatedStorage.Events.ToggleCrateGui:FireClient(Player, Crate)
game.ReplicatedStorage.Events.Import:FireClient(Player, "Your "..Brick.Name.." has arrived.")
end
end)
LocalScript:
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Root = Character:WaitForChild("HumanoidRootPart")
game.ReplicatedStorage.Events.ToggleCrateGui.OnClientEvent:Connect(function(Crate)
task.wait(1)
Crate:WaitForChild("BillboardGui").Enabled = true
while Crate ~= nil do
task.wait()
local Magnitude = (Root.Position - Crate.Position).Magnitude
Crate.BillboardGui.Distance.Text = Magnitude.." studs"
end
end)