Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why does this Conditional ALWAYS return true?

Okay so I have a fireball projectile that fires a replicated event that basically gives the global damage script that's inside of the projectile the name of the player. This way, the fireball won't damage the player that's casting the fireball. For some reason, the script ALWAYS thinks that the Player who is getting hit does not have the same name as the player who is casting it. It even thinks it if they have the DO have the same name, as I made the script print out both. For example, the output window will give me this: Player <--- Name of the Player who got hit/ Player <--- Name of the Player who shot the Fireball/ true <--- Does the Player who got hits' name not equal the player who shot the fireballs' name? Here's the fireball (local)script:

local variable cooldownFS = 1
local mouse = game.Players.LocalPlayer:GetMouse()
function shootFS()
	if cooldownFS == 1 then
		print("Works")
		cooldownFS = 0
	local fireballs = Instance.new("Part")
	fireballs.TopSurface = "Smooth"
	fireballs.BottomSurface = "Smooth"
	fireballs.BrickColor = BrickColor.new("Really red")
	fireballs.Transparency = 0.3
	fireballs.Size = Vector3.new(2,2,2)
	fireballs.CFrame = game.Players.LocalPlayer.Character.Torso.CFrame *CFrame.new(0,0,-6)
	fireballs.Parent = game.Workspace
	fireballs.Anchored = true
	fireballs.CanCollide = true
	local damage = script.Damage:clone()
	damage.Parent = fireballs
	damage.Disabled = false
	local re = Instance.new("RemoteEvent")
	re.Parent = game.Workspace
	re.Name = "re"
	re:FireServer()
	local mesh = Instance.new("SpecialMesh", fireballs)
	mesh.MeshType = "Sphere"
	local fire = Instance.new("Fire", fireballs)
	fire.Heat = 8
	fire.Size = 20
	local bv2 = Instance.new("BodyVelocity")
	bv2.maxForce = Vector3.new(math.huge,math.huge,math.huge)
	bv2.velocity =  (mouse.Hit.p-game.Players.LocalPlayer.Character.Torso.CFrame.p).unit*60
	--game.Players.LocalPlayer.Character.Torso.Anchored = true
		for i = 1,13 do
		fireballs.Mesh.Scale = fireballs.Mesh.Scale +Vector3.new(0.5,0.5,0.5)
		wait()
	end
	bv2.Parent = fireballs
	fireballs.Anchored = false
	wait(2)
	--game.Players.LocalPlayer.Character.Torso.Anchored = false
	fireballs:Destroy()
	wait(1.5)
	cooldownFS = 1
	end
end
script.Parent.Activated:connect(shootFS)

Here's the damage (Server)script:

wait()
local enabled = false
local re = game.Workspace.re
re.OnServerEvent:connect(function(player)
	 Own = player
	re.Name = "re"..player.Name
end)
wait()
--print(Own)
function Damage(hit)
	wait(1)
	local h = hit.Parent:FindFirstChild("Humanoid")
	local t = hit.Parent:FindFirstChild("Torso")
	if t then
		script.Parent.CanCollide = false
	end
	print(Own)
	print(h.Parent)
	print(h.Parent.Name ~= Own)
	if h and not enabled and h.Parent.Name ~= Own then
		print("Oops")
		enabled = true
		for i = 1,10 do
			h.Health = h.Health - 2
			wait(1/15)
		end
	end
	script:Destroy()
	enabled = false
	wait(3)
	game.Workspace.re:Destroy()
end
script.Parent.Touched:connect(Damage)

Additionally, Here's the Workspace: http://imgur.com/V89EOWg

3 comments

0

" local variable cooldownFS = 1 " well, you already failed.

0

If you're not sure, technically it's not invalid syntax. It creates a local variable called 'variable', and then sets the global 'cooldownFS' to 1

0

Oh, lol. I never noticed that. I actually made this script a while back, and when I just got started scripting. Then I added more stuff on to it and it became what you see now. Nevertheless, I still never saw that XD

1 answer

Whilst I believe there could be some issues with scope here (I see own defined in an anonymous function, but not outside?) you're checking the players name vs. the player object currently, as far as I can tell.

Within the OnServerEvent you set own to an instance of player, and access name via player.Name, so logically, your if statement should change to

    if h and not enabled and h.Parent.Name ~= Own.Name then

This discussion is preserved as it was. New answers, comments, and votes are closed.