Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago
Edited 5 years ago
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

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

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
Ad
Log in to vote
0
Answered by 5 years ago
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)
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. ISkyLordDoge 37 — 5y

Answer this question