You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? So I want this script when it the tool hits a player they get infected
-
What is the issue? So when I try to activate this tool I get an error in this screenshot and it doesn"t work
-
What solutions have you tried so far? I tried changing remote name.
I have tried every possible way, So I would be thankful if someone could help me. Sorry for the long code!
local Player = game:GetService("Players").LocalPlayer
local Mouse = Player:GetMouse()
local Remote = game:GetService("ReplicatedStorage"):WaitForChild("_Infection")
local Infected = false
local STrack
local Bound = {
Knife = false,
Scanner = false,
Healer = false
}
function Start(Time)
local Frame = script.Parent:WaitForChild("Info")
Frame:TweenPosition(UDim2.new(0.015, 0,0.275, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Quad)
for i = Time,0,-1 do
Frame.Time.Text = string.format("%d:%02d", math.floor(i/60), i%60)
if i == 0 then
Frame:TweenPosition(UDim2.new(-1, 0,0.275, 0), Enum.EasingDirection.In, Enum.EasingStyle.Quad)
end
wait(1)
end
end
function Infect()
Infected = true
local Blur = game:GetService("Lighting"):WaitForChild("InfectedBlur")
local CC = game:GetService("Lighting"):WaitForChild("InfectedCC")
local hit
spawn(function()
while wait(0.5) do
hit = nil
end
end)
Blur.Enabled = true
CC.Enabled = true
local Frame = script.Parent:WaitForChild("Infected")
Frame:TweenPosition(UDim2.new(0.777, 0,0.858, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Quad)
Player.Character.HumanoidRootPart.Touched:Connect(function(Part)
if Infected and not hit then
hit = Part
if hit.Parent then
if hit.Parent:FindFirstChild("Humanoid") then
local Target = hit.Parent.Name
Remote:InvokeServer({
Request = "Infect",
Target = Target
})
elseif hit.Parent.Parent and hit.Parent.Parent:FindFirstChild("Humanoid") then
local Target = hit.Parent.Parent.Name
Remote:InvokeServer({
Request = "Infect",
Target = Target
})
end
end
end
end)
end
function Cure()
Infected = false
local Blur = game:GetService("Lighting"):WaitForChild("InfectedBlur")
local CC = game:GetService("Lighting"):WaitForChild("InfectedCC")
Blur.Enabled = false
CC.Enabled = false
local Frame = script.Parent:WaitForChild("Infected")
Frame:TweenPosition(UDim2.new(1, 0,0.858, 0), Enum.EasingDirection.In, Enum.EasingStyle.Quad)
end
function HandleTool(Tool)
if Tool.Name == "Knife" then
if Bound.Knife then return false end
STrack = Player.Character:WaitForChild("Humanoid"):LoadAnimation(script.Swing)
local on = false
local hit
Bound.Knife = true
Tool.Activated:Connect(function()
on = true
STrack:Play()
wait(0.5)
on = false
hit = nil
end)
Tool.Handle.Touched:Connect(function(Part)
if on and not hit then
hit = Part
if hit.Parent then
if hit.Parent:FindFirstChild("Humanoid") then
local Target = hit.Parent.Name
Remote:InvokeServer({
Request = "Infect",
Target = Target
})
elseif hit.Parent.Parent and hit.Parent.Parent:FindFirstChild("Humanoid") then
local Target = hit.Parent.Parent.Name
Remote:InvokeServer({
Request = "Infect",
Target = Target
})
end
end
end
end)
elseif Tool.Name == "Scanner" then
if Bound.Scanner then return false end
local Frame = script.Parent:WaitForChild("Scanner")
Bound.Scanner = true
Tool.Activated:Connect(function()
if Mouse.Target then
if (Mouse.Target.Position - Player.Character.HumanoidRootPart.Position).Magnitude < 15 then
if Mouse.Target.Parent:FindFirstChild("Humanoid") then
if not game:GetService("Players"):FindFirstChild(Mouse.Target.Parent.Name) then return end
local Target = Mouse.Target.Parent.Name
local res = Remote:InvokeServer({
Request = "Scan",
Target = Target
})
if res == true then
Frame.Scanned.Text = "Scanned user: "..Target
Frame.Status.Text = "User is infected."
Frame.Status.TextColor3 = Color3.fromRGB(40, 170, 26)
else
Frame.Scanned.Text = "Scanned user: "..Target
Frame.Status.Text = "User is not infected."
Frame.Status.TextColor3 = Color3.fromRGB(255, 71, 71)
end
Frame.Visible = true
elseif Mouse.Target.Parent.Parent:FindFirstChild("Humanoid") then
if not game:GetService("Players"):FindFirstChild(Mouse.Target.Parent.Parent.Name) then return end
local Target = Mouse.Target.Parent.Parent.Name
local res = Remote:InvokeServer({
Request = "Scan",
Target = Target
})
if res == true then
Frame.Scanned.Text = "Scanned user: "..Target
Frame.Status.Text = "User is infected."
Frame.Status.TextColor3 = Color3.fromRGB(40, 170, 26)
else
Frame.Scanned.Text = "Scanned user: "..Target
Frame.Status.Text = "User is not infected."
Frame.Status.TextColor3 = Color3.fromRGB(255, 71, 71)
end
Frame.Visible = true
end
end
end
end)
Frame.Exit.MouseButton1Click:Connect(function()
Frame.Visible = false
end)
elseif Tool.Name == "Healer" then
if Bound.Healer then return false end
Bound.Healer = true
Tool.Activated:Connect(function()
if Mouse.Target then
if not game:GetService("Players"):FindFirstChild(Mouse.Target.Parent.Name) then return end
if Mouse.Target.Parent:FindFirstChild("Humanoid") then
Remote:InvokeServer({
Request = "Cure",
Target = Mouse.Target.Parent.Name
})
elseif Mouse.Target.Parent.Parent:FindFirstChild("Humanoid") then
if not game:GetService("Players"):FindFirstChild(Mouse.Target.Parent.Parent.Name) then return end
Remote:InvokeServer({
Request = "Cure",
Target = Mouse.Target.Parent.Parent.Name
})
end
end
end)
end
end
Remote.OnClientInvoke = function (data)
if data then
if data.Request == "Start" then
spawn(function()
Start(data.Time)
end)
end
if data.Request == "Infect" then
Infect()
end
if data.Request == "Cure" then
Cure()
end
if data.Request == "End" then
if Infected then
Cure()
end
end
end
return "ok"
end
Player.Character.ChildAdded:Connect(function(Obj)
if Obj:IsA("Tool") then
HandleTool(Obj)
end
end)
