And you said something about alway checking what team players are on instead of checking once
Want me to write a bit of code?
That would help yes I would like to check between both your code and my code
Orrr Im just guessing you can achieve that by making a while loop that check every 10 seconds if a player is in the killer team it gives them the weapon??
for i,plr in pairs(game:GetService("Players"):GetChildren()) do -- loops through all children of Players
print(plr.Team) -- prints what team every player is on
end
Local code:
-- Client (LocalScript)
local replicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = replicatedStorage.RemoteEvent
local guiButton = -- Refer to your UIButton here
guiButton.MouseButton1Click:Connect(function()
remoteEvent:FireServer()
end)
- MouseButton1Click event documentation
- RemoteEvent:FireServer documentation
- Remote Events documentation
Server side code:
-- Server (Script)
local replicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = replicatedStorage.RemoteEvent
local tool = -- Reference to your weapon here
remoteEvent.OnServerEvent:Connect(function(player)
local character = player.Character
if (character) then
local backpack = player.Backpack
local isToolInBackpack = backpack:FindFirstChild(tool.Name)
local isToolEquipped = character:FindFirstChild(tool.Name)
if (isToolInBackpack or isToolEquipped) then
-- Decide how you want to handle the case
-- where a player who already has a weapon
-- clicks your UI Button again
-- In this example, I'll just exit from this listener
return
end
task.wait(toolCloneDelay) -- Decide how long you want to delay the cloning for
local toolClone = tool:Clone()
toolClone.Parent = backpack
end
end)
This example code, on a GUI button click, would clone a tool into the player’s backpack without allowing them to duplicate their tools.
EDIT: Just a question, did you also want to make sure the player is on the killer team when they click the GUI button?
Here is what I did
for i, players in pairs(game.Players:GetPlayers()) do
if players.TeamColor == KillersTeamColor then
local ClonedWeapon = Weapon:Clone()
ClonedWeapon.Parent = players.Backpack
end
end
this would work for giving the players on the killers team the right tools, but there are some possible issues here:
-
if this code is ran multiple times whenever a new killer is added, any players already on the killers team will receive duplicates of the tool
-
unless you have done so already, you will still need to set up the code for actually detecting the buttons input, and changing the teams of the player to the killers team (which personally i think makes sense to do the tool cloning and parenting here rather than looping over every single player)
edit: typo
edit 2: magic graciously gave you all the info you would need for addressing the second problem (link in case you missed it)
i did notice lol it just seems to have gone past everyone else
ok is there an event that checks if you currently have the tool in your backpack?
if plr.Backpack:FindFirstChild("toolname") then
I’d also recommend storing the killer in a variable for reference and to see if theyre still in the game etc
ofc Thank you lol im so stupid