I am currently working on a X26 Taser script. Basically game.Players:GetPlayerFromCharacter(mouse.Target.Parent)
is getting the Player shooting the taser instead of the Player who is mouse.Target.Parent
. I have no ideas why that is happening. If you know any way how to fix this problem, then please let me know.
Client Script:
local taser = script.Parent
local Player = game.Players.LocalPlayer
local Cursor = "http://www.roblox.com/asset/?id=8633031046"
local Hitmark = "http://www.roblox.com/asset/?id=8633031679"
local mouseicon = Player:GetMouse()
local RemoteEvent = script.Parent:WaitForChild("TaseEvent")
local TaserSoundEvent = script.Parent:WaitForChild("TaserSoundEvent")
local Loaded = true
local UserInputService = game:GetService("UserInputService")
local IsReloading = false
taser.Equipped:Connect(function(mouse)
mouseicon.Icon = Cursor
mouse.Button1Down:connect(function()
if Loaded == true then
TaserSoundEvent:FireServer(true)
Loaded = false
if mouse.Target then
if mouse.Target.Name ~= "Handle" then
if mouse.Target.Parent:WaitForChild("Humanoid") then
if game.Players:GetPlayerFromCharacter(mouse.Target.Parent) then
if (mouse.Target.Position - Player.Character.HumanoidRootPart.Position).magnitude <= 30 then
RemoteEvent:FireServer(game.Players:GetPlayerFromCharacter(mouse.Target.Parent), mouse.Hit.Position, true)
mouseicon.Icon = Hitmark
wait(.5)
mouseicon.Icon = Cursor
end
end
else
return
end
end
if mouse.Target.Name == "Handle" then
if mouse.Target.Parent.Parent:WaitForChild("Humanoid") then
if game.Players:GetPlayerFromCharacter(mouse.Target.Parent.Parent) then
if (mouse.Target.Position - Player.Character.HumanoidRootPart.Position).magnitude <= 30 then
RemoteEvent:FireServer(game.Players:GetPlayerFromCharacter(mouse.Target.Parent.Parent), mouse.Hit.Position, true)
mouseicon.Icon = Hitmark
wait(.5)
mouseicon.Icon = Cursor
end
end
end
end
end
end
end)
end)
UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.R then
if Loaded == false and IsReloading == false then
print("[X26] Reloading has started")
IsReloading = true
wait(3)
Loaded = true
print("[X26] Reloaded, ready to shoot.")
IsReloading = false
end
end
end
end)
taser.Unequipped:Connect(function()
mouseicon.Icon = 0
end)
Server Script:
local ClientEvent = script.Parent:WaitForChild("TaseEvent")
script.Parent.TaseEvent.OnServerEvent:Connect(function(Player, Pos)
local SoundID = "rbxassetid://7554633549"
local Sound = Instance.new("Sound")
Sound.SoundId = SoundID
Sound.Parent = Player.Character
Sound:Play()
Sound.Ended:Connect(function()
Sound:Destroy()
end)
local Humanoid = Player.Character:WaitForChild("Humanoid")
Humanoid.PlatformStand = true
ClientEvent:FireClient(Player, false)
wait(5.955)
Humanoid.PlatformStand = false
ClientEvent:FireClient(Player, true)
end)
Video of how the tase currently works:
https://gyazo.com/0aadd9d7d02351e7e2cd745143227832.mp4