Don’t you want every team to have a sword? Or just one team?
Scientists can’t explain why such simple scripts require 20+ replies for the solution.
The player won’t get a sword if they respawn.
Don’t you want every team to have a sword? Or just one team?
Scientists can’t explain why such simple scripts require 20+ replies for the solution.
The player won’t get a sword if they respawn.
Prolly forgot about that, one second.
Only one team… since its like a murder mystery game
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Teams = game:GetService("Teams")
local sword = ReplicatedStorage:WaitForChild("Sword")
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
if player.Team == Teams.Spys then
local humanoid = character:WaitForChild("Humanoid")
local swordClone = sword:Clone()
swordClone.Parent = player.Backpack
end
end)
end)
Yeah, I think this fixes it…
That didnt work There wasnt even an error
local function removeSword(player)
local sword = player.Backpack:FindFirstChild("Sword") or player.Character:FindFirstChild("Sword")
if sword then sword:Destroy() end
end
local function giveSword(player)
removeSword(player)
player.Character:WaitForChild("Humanoid"):EquipTool(game.ReplicatedStorage.Sword:Clone())
end
local function checkplayer(player)
if player.Team.Name == "Spys" then
giveSword(player)
else
removeSword(player)
end
end
game.Players.PlayerAdded:Connect(function(player)
player:GetPropertyChangedSignal("Team"):Connect(function()
checkplayer(player)
end)
player.CharacterAdded:Connect(function()
checkplayer(player)
end)
end)
Updated to fix below:
15:17:52.375 ServerScriptService.Script:2: attempt to index nil with ‘Backpack’ - Server - Script:2
15:17:52.534 Team is not a valid member of Model “ImNotAN00b_0kay” - Server - Script:12
Let’s try putting the sword in the backpack instead…
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Teams = game:GetService("Teams")
local sword = ReplicatedStorage:WaitForChild("Sword")
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
if player.Team == Teams.Spys then
local humanoid = character:WaitForChild("Humanoid")
local swordClone = sword:Clone()
swordClone.Parent = player.Backpack
end
end)
end)
More errors
15:19:33.214 ServerScriptService.Script:2: attempt to index nil with ‘FindFirstChild’ - Server - Script:2
15:19:33.215 ServerScriptService.Script:25: attempt to index nil with ‘FindFirstChild’ - Server - Script:25
Does the tool have a Handle inside? If “RequiresHandle” is enabled but it does not have an object named “Handle” inside it would do things like this possibly.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.