Started creating a chest loot system, where loot is supposed to spawn nearby a chest once that chest is opened by a player. Unfortunately, when sending over the center of the chest from client to server, it’s not sending over.
Here is the relevant portion of the local script, located inside of StarterCharacterScripts.
local Center = common_chest:WaitForChild("Center")
local OpenSound = Center:WaitForChild("Open")
local Taken = common_chest:WaitForChild("Open")
if Player:DistanceFromCharacter(Center.Position) <= Distance and Taken.Value == false then
Taken.Value = true
local ChestAnimation = common_chest:WaitForChild("ChestHumanoid"):LoadAnimation(common_chest:WaitForChild("ChestAnimation"))
ChestAnimation:Play()
OpenSound:Play()
wait(1)
print(Center)
ChestOpenedRemote:FireServer(Center, "Common")
ChestAnimation.Stopped:Connect(function()
game.Debris:AddItem(common_chest, 0.1)
end)
end
end
Here is the server script responsible for spawning the randomized loot.
ChestOpenedRemote.OnServerEvent:Connect(function(player, chest_location, chest_type)
if chest_type == "Common" then
local Loot = ChestLootFolder:WaitForChild("Common"):GetChildren()
local ran_amount = math.random(3)
for i = 1,ran_amount do
local RandomLoot = math.random(#Loot)
local ChosenLoot = Loot[RandomLoot]:Clone()
ChosenLoot.Parent = Workspace:WaitForChild("Obtainables")
ChosenLoot.CFrame = chest_location.CFrame + Vector3.new(math.random(-4,4), math.random(4) ,math.random(-4,4))
ChosenLoot.Anchored = false
end
end
end
Inside of the local script when printing Center, it prints the Center correctly.
However, inside of the server script when printing chest_location, of which is that same “Center” variable that was printed earlier on in the local script, it prints nil.
I am not entirely sure why Center is returning nil to the Server, even though Center is printing just fine from within the local script.
Any ideas?