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

my touched script is not working.its supposed to add 1 to an intvalue. why?

local tool = game.StarterPack.Tool
tool.Equipped:Connect(function()
	script.Parent.Touched:Connect(function(hit)
		local hum = hit.Parent:FindFirstChild("Humanoid")
		local p = game.Players:GetPlayerFromCharacter(hit.Parent)
		local stats = p:FindFirstChild("leaderstats").Water
		if hum and p and stats then
			stats.Value = stats.Value + 1
		end
	end)
	tool.Unequipped:Connect(function()
		script.Parent.Touched:Connect(function(hit)
			local hum = hit.ParentFindFirstChild
			if hum then
				wait()
			end
		end)
	end)
end)

this is a server script parented to a part it's supposed to add 1 to the "Water" value whenever the part is touched while a certain tool is equipped i don't get it what am i doing wrong

6 comments

0

on line 13 you missed a colon and parentheses.that might be the issue

0

on line 13 you missed a colon and parentheses.that might be the issue

0

nope that isn't the issue

0

does it output any error? If so, what is the error?

0

there's no error

0

See, the problem here is your are doing game.StarterPack with a server script. When using StarterPack or anything player related, you are supposed to use a local script and connect the 2 using remote events.

1 answer

On line 13, you missed a colon and a parentheses... that might fix your issue.

local tool = game.StarterPack.Tool
tool.Equipped:Connect(function()
    script.Parent.Touched:Connect(function(hit)
        local hum = hit.Parent:FindFirstChild("Humanoid")
        local p = game.Players:GetPlayerFromCharacter(hit.Parent)
        local stats = p:FindFirstChild("leaderstats").Water
        if hum and p and stats then
            stats.Value = stats.Value + 1
        end
    end)
    tool.Unequipped:Connect(function()
        script.Parent.Touched:Connect(function(hit)
            local hum = hit.Parent:FindFirstChild()
            if hum then
                wait()
            end
        end)
    end)
end)

2 comments

0

this isn't the issue

0

If it isn't sending an error then you most likely dont have a remote event connected which i'd try adding to see if that works.

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