Hey, so my goal for my script is to add a decal to the wall and to players whenever the player or the wall gets hit by the tomato, however, it is not working. There is no errors in the console to help explain why it is not working.
local Tool = script.Parent
local enabled = true
local THROW_FORCE = math.random(40, 120)
local MIN_THROW_DELAY = 1
local DECAL_ID = "rbxassetid://13510998982"
local IMPACT_SOUND_ID = "rbxassetid://8595980577"
local players = game:GetService("Players")
local canThrow = true
local MouseUpdate = Instance.new("RemoteEvent")
MouseUpdate.Name = "MouseUpdate"
MouseUpdate.Parent = Tool
local currentMousePosition = Vector3.new(0, 0, 0)
MouseUpdate.OnServerEvent:Connect(function(player, mousePos)
currentMousePosition = mousePos
end)
local function applyImpactEffects(hit, hitPosition, hitNormal, character)
if not hit or hit:IsDescendantOf(character) then return end
print("Testing did infact worked")
local decal = Instance.new("Decal")
decal.Texture = DECAL_ID
if hitNormal.X > 0.5 then
decal.Face = Enum.NormalId.Right
elseif hitNormal.X < -0.5 then
decal.Face = Enum.NormalId.Left
elseif hitNormal.Y > 0.5 then
decal.Face = Enum.NormalId.Top
elseif hitNormal.Y < -0.5 then
decal.Face = Enum.NormalId.Bottom
elseif hitNormal.Z > 0.5 then
decal.Face = Enum.NormalId.Back
else
decal.Face = Enum.NormalId.Front
end
decal.Parent = hit
game.Debris:AddItem(decal, 10)
local emitter = Instance.new("ParticleEmitter")
emitter.Rate = 15
emitter.Lifetime = NumberRange.new(0.3, 0.6)
emitter.Speed = NumberRange.new(2, 5)
emitter.Texture = DECAL_ID
emitter.Parent = hit
game.Debris:AddItem(emitter, 1)
local sound = Instance.new("Sound")
sound.SoundId = IMPACT_SOUND_ID
sound.Volume = 0.5
sound.Parent = hit
sound:Play()
if hit.Parent:FindFirstChild("Humanoid") and hit.Parent ~= character then
local sound2 = Instance.new("Sound")
sound2.SoundId = IMPACT_SOUND_ID
sound2.Volume = 0.5
sound2.Parent = hit.Parent:FindFirstChild("HumanoidRootPart") or hit
sound2:Play()
end
end
local function onActivated()
if not enabled or not canThrow then return end
enabled = false
canThrow = false
local character = Tool.Parent
local humanoid = character:FindFirstChild("Humanoid")
local torso = character:FindFirstChild("Torso") or character:FindFirstChild("HumanoidRootPart")
if not humanoid or not torso then return end
local handle = Tool.Handle:Clone()
handle.Anchored = false
handle.CanCollide = true
handle.Parent = workspace
handle.Name = "Handle"
local offsetDistance = 2
local throwDirection = (currentMousePosition - torso.Position).Unit
handle.CFrame = torso.CFrame * CFrame.new(throwDirection * offsetDistance)
handle:ApplyImpulse(throwDirection * THROW_FORCE * handle:GetMass())
handle:SetNetworkOwner(nil)
if Tool.Handle:FindFirstChild("BiteSound") then
Tool.Handle.BiteSound:Play()
end
handle.Touched:Connect(function(hit)
local hitNormal = (hit.Position - handle.Position).Unit
applyImpactEffects(hit, hit.Position, hitNormal, character)
handle:Destroy()
end)
-- Optional: Setup collision groups if needed, but you can skip this if debugging.
-- local PhysicsService = game:GetService("PhysicsService")
-- PhysicsService:RegisterCollisionGroup("TomatoGroup")
-- handle.CollisionGroup = "TomatoGroup"
if #players:GetPlayers() >= 6 then
game.Debris:AddItem(handle, 3)
else
game.Debris:AddItem(handle, 3000)
end
Tool:Destroy()
end
local function onEquipped()
if Tool.Handle:FindFirstChild("EquipSound") then
Tool.Handle.EquipSound:Play()
end
end
Tool.Activated:Connect(onActivated)
Tool.Equipped:Connect(onEquipped)