Hello, I have created a script where when you say a word it does a function however it only does a function if that specific word is in a folder, This script throws a object at someone such as a crate or a bin, However if they arent in the folder then it doesnt work. The script works fine the first time however it doesnt work if i try it again.
Heres the script:
game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
Player.Chatted:Connect(function(Word)
Word = string.lower(Word)
for i, v in pairs(game.ReplicatedStorage.Objects:GetChildren()) do
if Word == string.lower(v.Name) and not Character:FindFirstChild("ObjectThrowingCooldown") then
local ObjectThrowingParticle = game.ReplicatedStorage.Particles.ObjectThrowingParticle:Clone()
ObjectThrowingParticle.CFrame = Character:WaitForChild("RightHand").CFrame
local WeldConstrait = Instance.new("WeldConstraint", ObjectThrowingParticle)
WeldConstrait.Part0 = ObjectThrowingParticle
WeldConstrait.Part1 = Character:WaitForChild("RightHand")
ObjectThrowingParticle.Anchored = false
ObjectThrowingParticle.Parent = Character:WaitForChild("RightHand")
task.spawn(function()
ObjectThrowingParticle.ParticleEmitter.Enabled = true
end)
local Cooldown = Instance.new("StringValue", Character)
Cooldown.Name = "ObjectThrowingCooldown"
Character:WaitForChild("Humanoid").WalkSpeed = 8
game.ReplicatedStorage.Remotes.SFX:FireClient(Player, "FOV", 95)
game.ReplicatedStorage.Remotes.ObjectThrowing:FireClient(Player, v)
end
end
return end)
end)
end)
Blockquote
Heres a video: