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

Can't access IntValue from different scripts ?

I have 2 different scripts, a LocalScript and a regular Script, that are both trying to access the same IntValue when you click the part which stores it.

The regular script, using a ClickDetector:

local function clicked()
	local health = script.Parent.IntValue

	health.Value = health.Value - 1

	-- destroy when 0 etc.
end

script.Parent.ClickDetector.MouseClick:Connect(clicked)

The LocalScript for an "axe" tool that makes damages a little bit more:

local function clicked(tree)
	local health = tree.IntValue

	health.Value = health.Value - 5

	-- again destroy when 0 etc.
end

script.Parent.Equipped:Connect(function(Mouse)
	Mouse.Button1Down:Connect(function()
		if Mouse.Target.Name == "Tree" then
			clicked(Mouse.Target)
		end
	end)
end)

The IntValue starts at 10 and gets destroyed when it's <= 0.

An example of my issue is:

player clicks tree without tool 3 times: health is now 7

player clicks tree with axe: health is now 2

player clicks without axe once more: health is now 6

The regular click seems to not get the updated IntValue when it is changed by the axe.

Any thoughts on how I can fix this? Thanks!

1 comment

0

you dont have to you a local script

1 answer

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