10 Hours ago @EmbatTheHybrid Helped me fix my problem with the ball not going to the player when the the player chats “:ball” Now he suggested me using FindChildOfClass to see if the player has the ball. So the script wouldn’t give the player another ball if the player already has one. But its not quiet working how I wanted it to. I never used FindChildOfClass before so I tried avoiding it cause I knew I would do it wrong and mess up the script.
The Code:
local RepStorage = game.ReplicatedStorage
local HasFootball = game.StarterPlayer.StarterCharacterScripts.Scripts.Values:WaitForChild("HasFootball")
local Football = RepStorage.Objects:WaitForChild("Football")
game.Players.PlayerAdded:Connect(function(Player)
Player.Chatted:Connect(function(Text)
if Text:lower() == ":ball" then
print("Gave a football to " .. Player.DisplayName)
Football:Clone().Parent = Player.Backpack
end
if Football.Parent == Player.Backpack then
HasFootball.Value = true
if HasFootball.Value == true then
script.Disabled = true
else
script.Disabled = false
end
end
end)
end)
You’re checking for the original football object’s parent instead of the cloned football. Try this:
game.Players.PlayerAdded:Connect(function(Player)
Player.Chatted:Connect(function(Text)
local footballClone
if Text:lower() == ":ball" then
print("Gave a football to " .. Player.DisplayName)
footballClone = Football:Clone()
footballClone.Parent = Player.Backpack
end
if footballClone then
HasFootball.Value = true
if HasFootball.Value == true then
script.Disabled = true
else
script.Disabled = false
end
end
end)
end)
local RepStorage = game.ReplicatedStorage
local Football = RepStorage.Objects:WaitForChild("Football")
game.Players.PlayerAdded:Connect(function(Player)
Player.Chatted:Connect(function(Text)
if Text:lower() == ":ball" then
print("Gave a football to " .. Player.DisplayName)
local hasToolInCharacter = Player.Character and Player.Character:FindFirstChildOfClass("Tool")
if hasToolInCharacter and hasToolInCharacter.Name == Football.Name then
print("Already has tool")
return
end
for _,tool in pairs(Player.Backpack:GetChildren()) do
if tool.Name == Football.Name then
return
end
end
Football:Clone().Parent = Player.Backpack
end
end)
end)
Checks if you have the tool in your character and if you do and it’s name is Football, return, other wise, go through your backpack and if finds one there, return, which should hopefully end the event there. If the return in the loop doesn’t work, then you cna make a variable that is true if it found a tool with that name or false if it didn’t, and return the event if it’s true, you don’t need to disable any scripts or use any values for this