How would I go about making it where when you have a tool in your hand, and click, it will play a sound?
(In my case it’s a cup, and when you click it makes a slurp noise, how would I do that?)
How would I go about making it where when you have a tool in your hand, and click, it will play a sound?
(In my case it’s a cup, and when you click it makes a slurp noise, how would I do that?)
Wrote some code below (didn’t test it) that might work. Tools have a property called .Activated that fires when the player clicks and the tool is equip. You can use that to play a sound like the slurp.
--Variables
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
--Checks if the tool is in the backpack
local selectedTool = player:WaitForChild("Backpack"):WaitForChild("selectedTool")
--If not in the backpack, checks if its currently equipped
if not selectedTool then
selectedTool = character:WaitForChild("selectedTool")
end
--Sound variable
local sound = Instance.new("Sound")
sound.Parent = selectedTool
--Plays crab rave
sound.SoundId = "rbxassetid://5410086218"
--Activated fires when the player clicks while the tool is activated
selectedTool.Activated:Connect(function()
sound:Play()
end)
Where do i insert this script into? The handle?
--Variables
local selectedTool = script.Parent
--Sound variable
local sound = Instance.new("Sound")
sound.Parent = selectedTool
--Plays crab rave
sound.SoundId = "rbxassetid://5410086218"
--Activated fires when the player clicks while the tool is activated
selectedTool.Activated:Connect(function()
sound:Play()
end)
If you’re going to put the script in the tool, write it like I did above. (new version)
Wow your a life saver! This taught me alot, thanks!
(mark as solution, i’m trying to get regular lol)
Will do! Goodluck on getting it!