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

Would I use Enum for an IntValue in my script?

I think it is for numbers which makes since and I want to use it in my script for an IntValue.

This script wont work and this is why I think I might need Enum

local function partTouched(onTouch)
	local leaderstats = game.Players:FindFirstChild("Folder")
		local intvalue = leaderstats:FindFirstChild("IntValue")
		if intvalue.Name == "FlexBux" then
			intvalue.Value = intvalue.Value + 20
		end
	end

script.Parent.Touched:Connect(partTouched)

here is what it says in the output:

16:09:51.715 - Workspace.Lobby.Obby.Part.Script:3: attempt to index nil with 'FlexBux'<

2 answers

✓ Accepted answer

Hey ScriptsALot!

You need to check whether the part touching is a player or not. If a different part is touching it, the exact same function will go for a part, leading an error, as there is no "leaderstats" in a part. You also look for an IntValue WITH THE NAME, IntValue, not with the name Flexbux. Try this script:

function partTouched(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if player then
        if player.leaderstats:FindFirstChild("FlexBux") then
              player.leaderstats.FlexBux.Value = player.leaderstats.FlexBux.Value + 1
        end
   end
end

script.Parent.Touched:Connect(partTouched)

Hope this helped, LennyPlayzYT

I would preferably do like this.

local function OnTouch(Touched)

   local FlexBux = game.Players.LocalPlayer.leaderstats.FlexBux

   FlexBux.Value = FlexBux.Value + 1
end)

script.Parent.Touched:Connect(OnTouch)

3 comments

0

When I use that it gives me in the output 16:38:28.717 - Workspace.Lobby.Obby.Part.Script:7: Expected identifier when parsing expression, got ')'

0

oh that means you need to add an end

0

why would i need another end there is no if statements or anything

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