I already have a whistle union and I know how to make it into a tool but I still need a script that plays a selected whistle noise and has a cool down of 5 (for example.) I also want it to display text above the player that is using the tool. Any help will be heavily appreciated. Thanks in advance
This is quite easy
local Debounce = true
local WhistleTool = script.Parent
local CurrentCharacter = nil
local WhistleSoundID = 0 -- put the id of the whistle sound here! (just the numbers)
local TextlabelTexts= {"CHARGE!", "MOVE FORWARD!"} -- You can add or change the texts to whatever you want, it picks them randomly! (make sure to add "," (comma) to separate them though!)
WhistleTool.Equipped:Connect(function()
CurrentCharacter = WhistleTool.Parent
end)
WhistleTool.Activated:Connect(function()
if CurrentCharacter == nil then return end
if Debounce == false then return end
Debounce = false
local HRP = CurrentCharacter.HumanoidRootPart
local ChosenText = TextlabelTexts[math.random(1,#TextlabelTexts)]
local SFX = Instance.new("Sound",HRP)
SFX.SoundId = "rbxassetid://" .. WhistleSoundID
SFX:Play()
game:GetService("Debris"):AddItem(SFX,SFX.TimeLength+0.1)
local TextAttachment = Instance.new("Attachment",HRP)
local BillBoardUI = Instance.new("BillboardGUI",TextAttachment)
BillBoardUI.Size = Udim2.new(25,0,5,0)
local TextLabel = Instance.new("TextLabel",BillBoardUI)
TextLabel.TextColor3 = Color3.FromRGB(255,255,255)
TextLabel.Size = Udim2.new(1,0,1,0)
TextLabel.BackgroundTransparency = 1
TextLabel.Text = ChosenText
TextAttachment.Position = Vector3.new(0,7,0)
game:GetService("Debris"):AddItem(TextAttachment",5)
task.wait(5)
Debounce = true
end)
this might have some errors though, since i wrote it on mobile! but… it’s gonna be easy fix:D
Thanks for the help!! I know that you said that if there are some errors it’ll be easy to fix but I don’t know how to as I never scripted before (did not even try before) I put a script inside the tool, got the sound id but it does not seem to be working. Here’s a screenshot:
Even if this is one of the most easy fixes ever, I still need help
Oop! I forgot to add "
local Debounce = true
local WhistleTool = script.Parent
local CurrentCharacter = nil
local WhistleSoundID = 0 -- put the id of the whistle sound here! (just the numbers)
local TextlabelTexts= {"CHARGE!", "MOVE FORWARD!"} -- You can add or change the texts to whatever you want, it picks them randomly! (make sure to add "," (comma) to separate them though!)
WhistleTool.Equipped:Connect(function()
CurrentCharacter = WhistleTool.Parent
end)
WhistleTool.Activated:Connect(function()
if CurrentCharacter == nil then return end
if Debounce == false then return end
Debounce = false
local HRP = CurrentCharacter.HumanoidRootPart
local ChosenText = TextlabelTexts[math.random(1,#TextlabelTexts)]
local SFX = Instance.new("Sound",HRP)
SFX.SoundId = "rbxassetid://" .. WhistleSoundID
SFX:Play()
game:GetService("Debris"):AddItem(SFX,SFX.TimeLength+0.1)
local TextAttachment = Instance.new("Attachment",HRP)
local BillBoardUI = Instance.new("BillboardGUI",TextAttachment)
BillBoardUI.Size = Udim2.new(25,0,5,0)
local TextLabel = Instance.new("TextLabel",BillBoardUI)
TextLabel.TextColor3 = Color3.FromRGB(255,255,255)
TextLabel.Size = Udim2.new(1,0,1,0)
TextLabel.BackgroundTransparency = 1
TextLabel.Text = ChosenText
TextAttachment.Position = Vector3.new(0,7,0)
game:GetService("Debris"):AddItem("TextAttachment",5)
task.wait(5)
Debounce = true
end)
Unfortunately still doesn’t work, the “Udim2” is still as an “unknown global”
You muse use UDim2
not Udim2
I forgot to ask, is this supposed to be a local or normal script?
And also there’s this:
local Debounce = true
local WhistleTool = script.Parent
local CurrentCharacter = nil
local WhistleSoundID = 0 -- put the id of the whistle sound here! (just the numbers)
local TextlabelTexts= {"CHARGE!", "MOVE FORWARD!"} -- You can add or change the texts to whatever you want, it picks them randomly! (make sure to add "," (comma) to separate them though!)
WhistleTool.Equipped:Connect(function()
CurrentCharacter = WhistleTool.Parent
end)
WhistleTool.Activated:Connect(function()
if CurrentCharacter == nil then return end
if Debounce == false then return end
Debounce = false
local HRP = CurrentCharacter.HumanoidRootPart
local ChosenText = TextlabelTexts[math.random(1,#TextlabelTexts)]
local SFX = Instance.new("Sound",HRP)
SFX.SoundId = "rbxassetid://" .. WhistleSoundID
SFX:Play()
game:GetService("Debris"):AddItem(SFX,SFX.TimeLength+0.1)
local TextAttachment = Instance.new("Attachment",HRP)
local BillBoardUI = Instance.new("BillboardGui",TextAttachment)
BillBoardUI.Size = UDim2.new(25,0,5,0)
local TextLabel = Instance.new("TextLabel",BillBoardUI)
TextLabel.TextColor3 = Color3.FromRGB(255,255,255)
TextLabel.Size = UDim2.new(1,0,1,0)
TextLabel.BackgroundTransparency = 1
TextLabel.Text = ChosenText
TextAttachment.Position = Vector3.new(0,7,0)
game:GetService("Debris"):AddItem("TextAttachment",5)
task.wait(5)
Debounce = true
end)
normal script btww
Instance.new("BillboardGui")
I think in your case you should use a local script, when I configure UI i’m always using local script.
Also do this if you using local script.
local player = game.Players.LocalPlayer
local currentCharacter = player.Character
I’ll try doing that hopefully it works
With a local script and the code that @xDZweird provided it’s still the same error but instead of it being
Players.Asasine_k.Backpack.Whistle.Script:30:
it is now
Players.Asasine_k.Backpack.Whistle.LocalScript:32:
Can you resend the actual localscript please
local Debounce = true
local WhistleTool = script.Parent
local CurrentCharacter = nil
local WhistleSoundID = 0 -- put the id of the whistle sound here! (just the numbers)
local TextlabelTexts= {"CHARGE!", "MOVE FORWARD!"} -- You can add or change the texts to whatever you want, it picks them randomly! (make sure to add "," (comma) to separate them though!)
WhistleTool.Equipped:Connect(function()
CurrentCharacter = WhistleTool.Parent
end)
WhistleTool.Activated:Connect(function()
if CurrentCharacter == nil then return end
if Debounce == false then return end
Debounce = false
local HRP = CurrentCharacter.HumanoidRootPart
local ChosenText = TextlabelTexts[math.random(1,#TextlabelTexts)]
local SFX = Instance.new("Sound",HRP)
SFX.SoundId = "rbxassetid://" .. WhistleSoundID
SFX:Play()
game:GetService("Debris"):AddItem(SFX,SFX.TimeLength+0.1)
local TextAttachment = Instance.new("Attachment",HRP)
local BillBoardUI = Instance.new("BillboardGui",TextAttachment)
BillBoardUI.Size = UDim2.new(25,0,5,0)
local TextLabel = Instance.new("TextLabel",BillBoardUI)
TextLabel.TextColor3 = Color3.fromRGB(255,255,255)
TextLabel.Size = UDim2.new(1,0,1,0)
TextLabel.BackgroundTransparency = 1
TextLabel.Text = ChosenText
TextAttachment.Position = Vector3.new(0,7,0)
game:GetService("Debris"):AddItem("TextAttachment",5)
task.wait(5)
Debounce = true
end)
and no, it’s not necessary to make an UI get created through LocalScript.
It now seems to work but the sound doesn’t play and the text doesn’t dissapear.
local Debounce = true
local WhistleTool = script.Parent
local CurrentCharacter = nil
local WhistleSoundID = 0 -- put the id of the whistle sound here! (just the numbers)
local TextlabelTexts= {"CHARGE!", "MOVE FORWARD!"} -- You can add or change the texts to whatever you want, it picks them randomly! (make sure to add "," (comma) to separate them though!)
WhistleTool.Equipped:Connect(function()
CurrentCharacter = WhistleTool.Parent
end)
WhistleTool.Activated:Connect(function()
if CurrentCharacter == nil then return end
if Debounce == false then return end
Debounce = false
local HRP = CurrentCharacter.HumanoidRootPart
local ChosenText = TextlabelTexts[math.random(1,#TextlabelTexts)]
local SFX = Instance.new("Sound",HRP)
SFX.SoundId = "rbxassetid://" .. WhistleSoundID
SFX:Play()
game:GetService("Debris"):AddItem(SFX,15)
local TextAttachment = Instance.new("Attachment",HRP)
local BillBoardUI = Instance.new("BillboardGui",TextAttachment)
BillBoardUI.Size = UDim2.new(25,0,5,0)
local TextLabel = Instance.new("TextLabel",BillBoardUI)
TextLabel.TextColor3 = Color3.fromRGB(255,255,255)
TextLabel.Size = UDim2.new(1,0,1,0)
TextLabel.BackgroundTransparency = 1
TextLabel.Text = ChosenText
TextAttachment.Position = Vector3.new(0,7,0)
game:GetService("Debris"):AddItem(TextAttachment,5)
task.wait(5)
Debounce = true
end)
It now works but is there any way to make the text bigger or change the font?
I am very sorry for most likely wasting your time, but I really want the game done. Thanks in advance.