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

I don't know why the script is assuming this parameter as the touched part. '?'

local config = script.Configuration

game.Workspace.Part.Touched:Connect(function(player)
	if player:GetPlayerFromCharacter() then
		if player:GetRankInGroup(config.GroupId) >= config.Rank then
			game.Workspace.Part:Destroy()
		end
	end
end)

How might I make this script think the parameter as a player? (The script is inside the StarterCharacterScripts, if this may help.)

2 answers

✓ Accepted answer

You are using the** touched** event and **GetPlayerFromCharacter() **incorrectly.

The Touched event doesn't pass a player it passes the part that touched that part

GetPlayerFromCharacter() -- Requires a potential character in it's paramaters

.Touched:Connect(function(hit) -- Hit is the part that touched the part your listening for touch
	local potentialPlayer = game.Players:GetPlayerFromCharacter(hit.Parent)
	if potentialPlayer then -- Must be a player since it returned true
		-- Then search for their rank etc
	end
end)

Also if this is meant to be client sided then it's completely pointless to even bother getting the player from the touched event.

If this helps an upvote or solve would be greatly appreciated.

  • Best Regards, - Syn
game.Players.PlayerAdded:Connect(function(player)
	game.Workspace.Part.Touched:Connect(function()	    
		if player then
        	if player:GetRankInGroup(886313) >= 1 then
            	game.Workspace.Part:Destroy()
        	end
    	end
	end)
end)

1 comment

0

I'm sorry, that you feel I'm disrespecting you; but actually I forgot to put it in the StarterCharacterScripts and it didn't work, so I'll accept your answer. Really sorry.

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