generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: How do I make this sound local?

Previous Thread :: Next Thread 
550GB is not online. 550GB
Joined: 05 Jan 2014
Total Posts: 414
13 Oct 2016 06:34 AM
This is supposed to be a hitmarker script that plays a sound and a gui image every time you get a hit; the only problem is everyone hears your hit and i need it to be local. It fetches the sound from the lighting in a model called "sounds" Here's the script:

local gui = script.Parent;
local hit = gui:WaitForChild("hit");
local mouse = game:GetService("Players").LocalPlayer:GetMouse();
local lastRun;

game:GetService("Workspace").DescendantAdded:connect(function(inst)
if inst.Name == "creator" and inst:IsA("ObjectValue") and inst.Value == game:GetService("Players").LocalPlayer then
if not hit.Visible then
local soundfx = game:GetService("Lighting").sounds.hit:Clone();
soundfx.Parent = game:GetService("Players").LocalPlayer;
soundfx:Play();
game:GetService("Debris"):AddItem(soundfx, .5);
hit.Visible = true;
end;
lastRun = tick();
wait(.5)
if tick() - lastRun < .5 then return end;
hit.Visible = false;
end;
end);

game:GetService("RunService").RenderStepped:connect(function()
hit.Position = UDim2.new(0,mouse.X-50,0,mouse.Y-50);
end);

If anyone could rewrite this to make it a local sound instead that would be a huge help.
Report Abuse
Cheater is not online. Cheater
Joined: 29 Jun 2007
Total Posts: 5258
13 Oct 2016 06:52 AM
Drop it into the PlayerGui, not the Player itself.
Report Abuse
550GB is not online. 550GB
Joined: 05 Jan 2014
Total Posts: 414
13 Oct 2016 07:01 AM
What? What do I replace in this script to make the sound local instead of everyone hearing the noise?
Report Abuse
Cheater is not online. Cheater
Joined: 29 Jun 2007
Total Posts: 5258
13 Oct 2016 07:05 AM
local gui = script.Parent;
local hit = gui:WaitForChild("hit");
local mouse = game:GetService("Players").LocalPlayer:GetMouse();
local lastRun;

game:GetService("Workspace").DescendantAdded:connect(function(inst)
if inst.Name == "creator" and inst:IsA("ObjectValue") and inst.Value == game:GetService("Players").LocalPlayer then
if not hit.Visible then
local soundfx = game:GetService("Lighting").sounds.hit:Clone();
soundfx.Parent = game:GetService("Players").LocalPlayer.PlayerGui; -- edited this line, but actually you can already drop the sound into "StarterGui" and it should do the trick I guess
soundfx:Play();
game:GetService("Debris"):AddItem(soundfx, .5);
hit.Visible = true;
end;
lastRun = tick();
wait(.5)
if tick() - lastRun < .5 then return end;
hit.Visible = false;
end;
end);

game:GetService("RunService").RenderStepped:connect(function()
hit.Position = UDim2.new(0,mouse.X-50,0,mouse.Y-50);
end);
Report Abuse
HlCOM is not online. HlCOM
Joined: 29 Mar 2009
Total Posts: 3332
13 Oct 2016 07:28 AM
whats with the :GetService spam

just do workspace.DescendantAdded and game.Players
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
13 Oct 2016 10:24 AM
your game obviosuly isnt FE. Thats your first problem.


Report Abuse
Praeval is not online. Praeval
Joined: 11 Oct 2016
Total Posts: 110
13 Oct 2016 10:25 AM
GetService() is personal preference.

It's not even useful enough to be considered a best practice, but theoretically it's better just in case ROBLOX changes the names of services. Also for consistency in code. I don't do that personally.


Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
13 Oct 2016 10:46 AM
"GetService() is personal preference.

It's not even useful enough to be considered a best practice, but theoretically it's better just in case ROBLOX changes the names of services. Also for consistency in code. I don't do that personally."


Actually, the wiki (And I) say otherwise.
GetService also attempts to initialize a service if it doesn't exist already. Not all services are initialized when the game starts. I don't know which ones exactly, but I do know that they exist.
However, most people glance over this, the most useful part of GetService.



'Returns a service with the class name requested. When called with the name of a service (such as Debris) it will return the instance of that service. If the service does not yet exist it will be created and the new service is returned.'


Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image