Hello there! I am making a PVP game and I want to make a fighting zone. I’m using the ZonePlus module.
I need to make it so the player’s tools get equipped when they enter a zone and get them unequipped when they leave. I am storing them in ReplicatedStorage
once they leave the zone.
Local script:
local FightZone = Zone.new(game.Workspace.FightingZone)
FightZone.playerEntered:Connect(function(player)
RepStorage.events.EquipTools:FireServer(player)
end)
FightZone.playerExited:Connect(function(player)
RepStorage.events.UnequipTools:FireServer(player)
end)
Server script:
game.Players.PlayerAdded:Connect(function(Player)
local Sword = game:GetService("ReplicatedStorage").Sword:Clone()
Sword.Parent = Player.Backpack
Sword.Name = Player.Name
end)
local RepStorage = game:GetService("ReplicatedStorage")
RepStorage.events.EquipTools.OnServerEvent:Connect(function(player)
for i, v in pairs(RepStorage:GetChildren()) do
if v.Name == player.Name then
v.Parent = player.Backpack
end
end
end)
RepStorage.events.UnequipTools.OnServerEvent:Connect(function(player)
local PlayerTools = player.Backpack:GetChildren()
for i, v in pairs(PlayerTools) do
v.Name = player.Name
v.Parent = RepStorage
end
end)
Any help will be appreciated. I know the code is messy, I just need a fix before I start to clean it up.