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

leaderstats is not a valid memeber of Part?

I was trying to make a script that changes the Value of a variable once an IntValue reached 10 or up. I ran the script and then saw that the output wrote out the error, "leaderstats is not a valid member of Part" Here is script that put out the error and the script associated with the error.

workspace.Wall.Touched:connect(function(player)
	Clicks = player.leaderstats.Clicks
	if Clicks.Value >= 10 then
		
	end
end)


game.Players.PlayerAdded:connect(function(player)
	stats = Instance.new("IntValue", player)
	stats.Name = "leaderstats"

	Clicks = Instance.new("IntValue", stats)
	Clicks.Name = "Clicks"
end)

Another script might need to be included. Please tell me if it does.

2 answers

Your problem is that when you check for the wall being touched, it gives you a part, like a foot or an arm. What you can do to fix this is:

workspace.Wall.Touched:connect(function(part)
   local player = game.Players:GetPlayerFromCharacter(part.Parent) 

   if player then 
	    Clicks = player.leaderstats.Clicks
	    if Clicks.Value >= 10 then
		--Do whatever you want here 
	    end
    end 
end)

So what this script does is it takes the parent of a part, for example, a arm, and checks to see if it a character of a player. We then have to check if the player actually exists and then you can do whatever.

I hope this helps!

1 comment

0

aw man. it didn't work. do you think that another script needs to be mentioned?

game.Players.PlayerAdded:connect(function(player)
    local stats = Instance.new("Folder", player)
    stats.Name = "leaderstats"

    local Clicks = Instance.new("IntValue", stats)
    Clicks.Name = "Clicks"
end)	

workspace.Wall.Touched:Connect(function(part)
	if part.Parent:FindFirstChild("Humanoid") then
		local player = game.Players:GetPlayerFromCharacter(part.Parent) 
		if player then 
			local Clicks = player.leaderstats.Clicks
			if Clicks.Value >= 10 then
		       		workspace.Wall.CanCollide = false
			end
		end 
	end
end)

4 comments

0

um.. im pretty sure that does not work.

0

please elaborate what you want this to do then.

0

once clicks value is over or equal to 10 im gonna have the wall's can collide property set to false.

0

edited, tell me if this is what you want.

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