Hello!
I just created a script to promote a person in my group using the http service, however it doesn't seem to work.
function promoteuser(..,..,..) print "This function is classified and works fine." end function promote(player) print "1" promouser((1240173),(8236279), player.userId) print "fin" end script.Parent.Touched:connect(promote)
The error is on line 7.
userId is not a valid member of Part
Can someone help?
Thanks!
The Touched event returns the part that touched the part that the event is focusing on. For example, part1 is the part we're focusing on (touching it will trigger the Touched event). Say a player's character's left leg touches it. In your case, the variable "player" is the left leg, not the player. So, I suggest you change the "player" variable to something that makes more sense with what we're dealing with here, like "part." After you do that, you use the GetPlayerFromCharacter()
method to get the player from his/her character. Your script would then look like this:
script.Parent.Touched:connect(function(part) --this is what yours does, I just like to write my events a different way if part.Parent:IsA("Model") then --this checks if the part's parent is a Model, since the player's character is a model local player = game.Players:GetPlayerFromCharacter(part.Parent) --this line will attempt to get a player from a character. if there's not a valid character, this will be nil, which is why we have the next line if player then promouser((1240173),(8236279), player.userId) end end end)
If this answer was helpful, please consider upvoting it and marking it as "accepted." Thanks!
The error explains what's going on. You're attempting to access "userId" from "player", but it's telling you that the variable "player" refers to a Part - and Parts don't have userIds.
Indeed, you say "script.Parent.Touched:connect(promote)", and a Touched event's argument is what touched (in this case) script.Parent. Thus, you need to convert the part to the player:
function promote(part) if part.Parent == nil then return end --ignore projectiles local player = game.Players:PlayerFromCharacter(part.Parent) if player == nil then return end --not a player --rest of promote here end
Also, make sure that nothing bugs if 'promote' gets triggered by the same player numerous times in a row (ex if multiple limbs touch 'script.Parent' at the same time).