Why does this script happen to all the Players and how to fix it

This is the Local Script

local RS = game:GetService("ReplicatedStorage")
local UIS = game:GetService("UserInputService")

local Plr = game.Players.LocalPlayer
repeat task.wait() until Plr.Character
local char = Plr.Character or Plr.CharacterAdded:Wait()
local Humanoid = char:WaitForChild("Humanoid")

local GomuGomuNoPistol = script:WaitForChild("Gomu Gomu No Pistol")
local GomuGomuNoPistolTrack = Humanoid:LoadAnimation(GomuGomuNoPistol)

local Event =  RS:WaitForChild("Events"):WaitForChild("Gomu")

local Tool = script.Parent

local Equipped = false
local CD = false

Tool.Equipped:Connect(function()
	Equipped = true
	Tool.Unequipped:Wait()
	Equipped = false
end)

UIS.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.E then
		if Equipped == true then
			if CD == false then
			CD = true
			GomuGomuNoPistolTrack:Play()
			Humanoid.AutoRotate = false
			Humanoid.WalkSpeed = 0
			wait(0.5)
			Event:FireServer()
			wait(0.8)
			Humanoid.WalkSpeed = 16
			Humanoid.AutoRotate = true
			wait(2)
			CD = false
			end
		end
	end
end)

and this is the Server Script After its Fired the Event

local RS = game:GetService("ReplicatedStorage")
local UIS = game:GetService("UserInputService")

local Event =  RS:WaitForChild("Events"):WaitForChild("Gomu")
local Tool = script.Parent

Event.OnServerEvent:Connect(function()
	local Character = Tool.Parent
	local RightArm = Character:WaitForChild("Right Arm")
	local Head = Character:WaitForChild("Head")
	
	local RightArmPart = Instance.new("Part")
	RightArm.Transparency = 1
	RightArmPart.Material = Enum.Material.SmoothPlastic
	RightArmPart.Name = ("RightArmPart")
	RightArmPart.Massless = true
	RightArmPart.CFrame = RightArm.CFrame
	RightArmPart.Size = RightArm.Size
	RightArmPart.CanCollide = false
	RightArmPart.Anchored = false
	RightArmPart.Orientation = RightArm.Orientation
	RightArmPart.Color = RightArm.Color
	RightArmPart.Parent = workspace
	
	local weld = Instance.new("ManualWeld")
	weld.Part0 = RightArmPart
	weld.Part1 = RightArm
	weld.C0 = weld.Part0.CFrame:ToObjectSpace(weld.Part1.CFrame)
	weld.Parent = weld.Part0
	
	local TweenService = game:GetService("TweenService")
	
	local PistolInfo = TweenInfo.new(0.3, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, true, 0)
	local ArmSpeed = Vector3.new(0,0,10)
	
	local pos = RightArmPart.CFrame + RightArmPart.CFrame.LookVector*5
	local Shockwave1 = RS.SW1:Clone()
	Shockwave1.Position = RightArm.CFrame * Vector3.new(5,0,0)
	Shockwave1.Orientation = pos.Position
	Shockwave1.Parent = workspace
	
	local PistolTweenSize = TweenService:Create(RightArmPart, PistolInfo, {Size = Vector3.new(1,50,1)})
	local TweenPos = TweenService:Create(weld, PistolInfo, {C0 = CFrame.new(0, 24, 0)}):Play()
	
	PistolTweenSize:Play()
	wait(0.6)
	RightArmPart:Destroy()
   	
	RightArm.Transparency = 0
end)

What happens is when they have there Tool Equipped if someone Activates the Event it will happen to them aswell

If you understand what im saying can someone help to prevent this?


this is what happens when i Click E while they have the Tool equipped

1 Like

Nevermind Fixed it Already

Just put the Event in the Tool

while youve got a solution, it isnt the most efficient. the reason this was happening is because your server script doesnt check who the event fired from. its just any time the event is fired, the code runs for every script. you should look into remote events cuz the OnServerEvent function has a parameter containing the player that fired the event

I mean it works Perfectly Fine so will doing this change anything?

Its more efficient. And with the way you have it, any changes made to one will have to be made for the others as well. For example what if you change it to a bindable event or remote function instead. Lastly the way i mentioned will make it easier to manage and its just a good habbit to get in.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.