Any errors in the output you are aware of?
No errors show up. Everything works, just the curing itself doesn’t work, and I can’t figure out how to make it only work on the person the tool touches instead of the one who holds it.
tool.Handle.Touched:Connect(function(hit)
local Player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if Player and Debounce == true then
Debounce = false
game.ReplicatedStorage.Cure1:FireServer(hit)
wait(1)
Debounce = true
end
end)
tool.Handle.Touched:Connect(function(hit)
local Player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if Player and Debounce == true then
Debounce = false
game.ReplicatedStorage.Cure1:FireServer(hit)
wait(1)
Debounce = true
end
end)
end)
Missing “end)”?
That doesn’t show up anywhere in the output, nothing in the actual script would correspond to that “end)”. There is only one function, one if then statement. Nothing else that gets required “end)”.
tool.Handle.Touched:Connect(function(part)
if part.Parent:FindFirstChild("Humanoid") and Debounce == true then
Debounce = false
game.ReplicatedStorage.Cure1:FireServer(part.Parent.Name)
wait(1)
Debounce = true
end
end)
I do not know what your trying to send through “FireServer(hit)”.
use collectionservice to handle the viruses, apply a tag to the character when they have gotten a virus, then have a bindable fire to a virus handler, when the bindable is recieved, check what type of virus it is, and give them the effects desired.
then, when you want to remove the disease, just use CollectionService:RemoveTag(disease)
, and re-send a bindable to the disease handler, with the disease value being false i recommend you have a boolvalue parameter in the bindable, saying whether to give a disease or not.
i find this tutorial pretty useful, but here is a devhub link also.
DevForum Tutorial [the one i like]
Developer Hub Tutorial
I’m trying to send another remote event to the local script in StarterPlayerScripts. Instead of going back to the one who held the tool, I want it to only work on the person who was touched.
(Your updated script doesn’t work either).
I’ll check it out and post an update after I mess around with it.
I listened to your advice and added an add tag and remove tag in certain parts of the local script and created a BindableEvent to ReplicatedStorage, but after that I got stuck. I do not know what a virus handler is, nor do I know how to continue with your advice.
I’ll admit I’m sort of beginner level and do not understand most definitions and tricks.
quick FYI, bindable events are like remote events that can be received by the same type of script. [ex. server script firing a bindable event, another server script can detect when that bindable event was fired, however remote events cannot do this]
code sample:
client:
--hit is the character that was hit with a needle
virusremote:FireServer("VirusName",hit) -- the true is whether to give disease or not
server:
virusremote.OnServerEvent:Connect(function(originalplr,disease,infectedplr,givedisease)
virusbindable:Fire(disease,infectedplr)
collectionservice:AddTag(infectedplr,disease)
end)
virus handler [also server script]
virusbindable.Event:Connect(function(disease,plr)
if disease == "coronavirus" then
-- apply effects
end
if disease == "remove disease"
collectionservice:RemoveTag(plr,collectionservice:GetTags(plr)
end
end)
sorry if i confused you, of course things such as collectionservice
and virusremote
you will have to define as variables
ex.
local collectionservice = game:GetService("CollectionService")
For the virus handler, I am a little confused on the code.
if disease == "coronavirus" then
-- apply effects
end
What do you mean by apply effects? Do you mean just disabling the disease, or is this supposed to be another way I can damage and slow down someone?
if disease == "remove disease"
collectionservice:RemoveTag(plr,collectionservice:GetTags(plr)
end
Are these two different diseases I am meant to put in the quotations?
Am I meant to keep “remove disease” as is?
Once again, sorry for all the questions. Just want to make sure I don’t mess this up.
yeah, where it says apply effects, thats where you do the effects of the disease you want. yes, you keep remove disease the same, when you want to remove a disease you will do virusremote:FireServer("remove disease",hit)
Jeez, I’m not even sure myself if I am doing this right, I’m learning so much in one night.
Here’s my current code, where do I put the " virusremote:FireServer("remove disease",hit)
" and have I put everything else in the right location?
Local Script (In StarterPlayerScripts)
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local CollectionService = game:GetService("CollectionService")
local virusremote = game.ReplicatedStorage.Cure1test
wait(10)
local Cough1Copy = game.ReplicatedStorage.Cough1:Clone()
Cough1Copy.Parent = Character.Head
local Cough2Copy = game.ReplicatedStorage.Cough2:Clone()
Cough2Copy.Parent = Character.Head
game.ReplicatedStorage.Cure1two.OnClientEvent:Connect(function()
print("RecievedClient")
wait(4)
ColdOn = false
end)
while true do
local newRandom
local oldRandom = newRandom
local chosenDisease
local oldchosenDisease= chosenDisease
if TuberOn == true then
for count = 1, 60 do
wait(1)
Character.Humanoid.Health = Character.Humanoid.Health - 1
Character.Humanoid.WalkSpeed = Character.Humanoid.WalkSpeed - .1
end
TuberOn = false
elseif FluOn == true then
for count = 1, 300 do
wait(1)
Character.Humanoid.Health = Character.Humanoid.Health - .1
Character.Humanoid.WalkSpeed = Character.Humanoid.WalkSpeed - .005
end
FluOn = false
elseif ColdOn == true then
CollectionService:AddTag(Character.Humanoid, "Cold")
for count = 1, 30 do
wait(8)
Cough1Copy:Play()
Character.Humanoid.WalkSpeed = Character.Humanoid.WalkSpeed - .4
wait(8)
Cough2Copy:Play()
end
ColdOn = false
CollectionService:RemoveTag(Character.Humanoid, "Cold")
end
do repeat
newRandom = math.random(20, 30)
wait()
until
newRandom ~= oldRandom
end
do repeat
chosenDisease = math.random(0, 100)
wait()
until
chosenDisease ~= oldchosenDisease
end
wait(newRandom)
print(chosenDisease)
TuberOn = false
FluOn = false
ColdOn = false
if chosenDisease >= 90 then
print("Tuberculosis!")
TuberOn = true
elseif chosenDisease >= 85 then
print("Flu!")
FluOn = true
elseif chosenDisease >= 60 then
print("Cold!")
ColdOn = true
elseif chosenDisease >= 0 then
print("None!")
end
end
Local Script (In tool in StarterPack)
local tool = script.Parent
local Debounce = true
local virusremote = game.ReplicatedStorage.VirusRemote
tool.Handle.Touched:Connect(function(hit)
local Player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if Player and Debounce == true then
Debounce = false
virusremote:FireServer("Cold", hit)
wait(1)
Debounce = true
end
end)
Server Script (In ServerScriptService)
local virusremote = game.ReplicatedStorage.VirusRemote
local virusbindable = game.ReplicatedStorage.VirusBindable
local collectionservice = game:GetService("CollectionService")
virusremote.OnServerEvent:Connect(function(originalplr,disease,infectedplr,givedisease)
virusbindable:Fire(disease,infectedplr)
collectionservice:AddTag(infectedplr,disease)
end)
Server Script (In ServerScriptService)
(Named Handler)
local collectionservice = game:GetService("CollectionService")
local virusbindable = game.ReplicatedStorage.VirusBindable
virusbindable.Event:Connect(function(disease,plr)
if disease == "Cold" then
print("GotCold!")
end
if disease == "remove disease" then
collectionservice:RemoveTag(plr,collectionservice:GetTags(plr))
end
end)
Sorry if this is a bit much honestly. I’m thankful you’re still helping me out.
So what you can do is place a value that identifies a player with the disease or not, and whenever you use the tool, and I’m assuming clicking on the player, it’ll fire to the server to check everything, such as if they can cure, if they have the tool (exploiters can clone the tool into their backpack), and if the player is sick or not. If nothing appears strange, then you can run the code that cures the player.
have you tested your current code? it seems like it would work.
I haven’t. I guess I probably should, give me a moment.
It doesn’t work, I just tested it. It didn’t stop the cold from lowering my walkspeed, but it did print “GotCold!”.
okay so basically, it does “work” the effects of the cold disease should be inside of the place where it says
if disease == "Cold" then
It still doesn’t work.
The code:
local collectionservice = game:GetService("CollectionService")
local virusbindable = game.ReplicatedStorage.VirusBindable
virusbindable.Event:Connect(function(disease,plr)
if disease == "Cold" then
local Cough1Copy = game.ReplicatedStorage.Cough1:Clone()
Cough1Copy.Parent = plr.Character.Head
local Cough2Copy = game.ReplicatedStorage.Cough2:Clone()
Cough2Copy.Parent = plr.Character.Head
print("GotCold!")
wait(8)
Cough1Copy:Play()
plr.Character.Humanoid.WalkSpeed = plr.Character.Humanoid.WalkSpeed - .4
wait(8)
Cough2Copy:Play()
end
if disease == "remove disease" then
collectionservice:RemoveTag(plr,collectionservice:GetTags(plr))
end
end)
What is Cough1Copy
and Cough2Copy
?