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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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 |
|
|
|
| 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 |
|
|