Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Help with a tool that sprays fire!?

Asked by 9 years ago

I want this script so when you click with the tool it will spray out fire and then the player(s) that touch it will take damage? Here is the script

Player = game.Players.LocalPlayer
Firegun = script.Parent
Fire = 20
mouse = Player:GetMouse()
Canisters = 10
function Shoot()
    if Fire > 0 then
        print("You have" .. Fire .. "fire and" .. Canisters .. "Canisters")
        Fire = Instance.new("Fire", Firegun)
        Fire.Heat = 15
        Fire.Size = 15
        Fire.Color = Color3.new(255,85)
        Fire.SecondaryColor = Color3.new(255,150,30)
    end
end
if Canisters < 1 then
    Fire.Enabled = false
Canisters = 1
wait(0.3)
Canisters = 2
wait(0.3)
Canisters = 3
wait(0.3)
Canisters = 4
wait(0.3)
Canisters = 5
wait(0.3)
Canisters = 6
wait(0.3)
Canisters = 7
wait(0.3)
Canisters = 8
wait(0.3)
Canisters = 9
wait(0.3)
Canisters = 10
Fire.Enabled = true
end
Firegun.Activated:connect(Shoot)

Ouput says Disconnected event because of exception and Players.Player1.Backpack.Firegun.SprayScript:7: attempt to compare number with userdata.Help!

2 answers

Log in to vote
1
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
9 years ago

Line 12: Color3 is called Color3, because there's three colors. Red, Green, and Blue. However, you only put in two colors.

Lines 3 and 9: You have two fire variables! One is the fire, and one is a number. Fire starts off equaling 20, but then you change it to equal a fire object. That's why you get the error. Once Fire equals an object instead of a number, you can't check if it's greater than 0.

Line 16: That code will only run once, NOT every time the tool is clicked. On top of that, Canisters will never be less than 1, because you never change it's value. I assume you want it to be an ammo sort of thing.

This will also never damage a player. There is no way for fire itself to do damage. You could use an invisible part the same size as the fire, though.

This is what you need to do to fix it. If you try and it still does not work, I'll help some more.

Ad
Log in to vote
-1
Answered by 9 years ago

Your issue is that you have two variables working together in a single function causing it to break. Simply change the local Fire at line 7 and line 3 to local Firea, I also changed Canisters to Local. This will help with the identification of the numbers, and the identification of Fire and Firea

Player = game.Players.LocalPlayer
Firegun = script.Parent
local Firea = 20
mouse = Player:GetMouse()
local Canisters = 10
function Shoot()
    if Firea > 0 then
        print("You have" .. Fire .. "fire and" .. Canisters .. "Canisters")
        Fire = Instance.new("Fire", Firegun)
        Fire.Heat = 15
        Fire.Size = 15
        Fire.Color = Color3.new(255,85)
        Fire.SecondaryColor = Color3.new(255,150,30)
    end
end
if Canisters < 1 then
    Fire.Enabled = false
Canisters = 1
wait(0.3)
Canisters = 2
wait(0.3)
Canisters = 3
wait(0.3)
Canisters = 4
wait(0.3)
Canisters = 5
wait(0.3)
Canisters = 6
wait(0.3)
Canisters = 7
wait(0.3)
Canisters = 8
wait(0.3)
Canisters = 9
wait(0.3)
Canisters = 10
Fire.Enabled = true
end
Firegun.Activated:connect(Shoot)

0
Excuse me, whoever just down voted me, you know straight were you can go. There was an issue with variables that happened to me once, he does have an overlapping variable which can be the issue. Also if I had 5 I'd downvote you. Jerk. micke3212 35 — 9y

Answer this question