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

I keep getting the error "player is not a valid member of DataModel", can someone help?

Asked by
L_DG 0
4 years ago
Edited 4 years ago

I asked someone, and they sent me on the right track. Still haven't figured this out.

local Player = game.player.Character
local char = Player.Character or Player.CharacterAdded:Wait()
local Button = script.Parent.FireButton

function OnClicked()

    script.Parent:Destroy()
    print(Player.."Hit me D:")
wait(.5)


local FirePet = game.ReplicatedStorage.FirePet


local xPosition = char.Torso.Position.X
local yPosition = char.Torso.Position.Y
local zPosition = char.Torso.Position.Z

local function AddFirePet()
    local FirePetCopy = FirePet:Clone()
    FirePetCopy.Parent = char.Torso



wait(1)
FirePetCopy.Position = Vector3.new(xPosition,yPosition,zPosition)

    print("Reset Positions")
end

do AddFirePet()

end

end  
Button.MouseButton1Click:connect(OnClicked)

1 answer

Log in to vote
1
Answered by
Norbunny 555 Moderation Voter
4 years ago
Edited 4 years ago

WARNING! You are using a local script, meaning that whatever you write there, will only be seen by the current player (client)! You should use RemoteEvents to create a client-server connection and replicate it to the server!

Documentation on RemoteEvents

And when using a LocalScript to get the current player you do game.Players.LocalPlayer

Fixing your code would be like:

local Player = game.Players.LocalPlayer
local char = Player.Character or Player.CharacterAdded:Wait()
local Button = script.Parent.FireButton

function OnClicked()
    script.Parent:Destroy() -- This deletes the script's parent and it's children(including the script! Be careful!)
    print(Player.."Hit me D:")
    wait(.5)


    local FirePet = game.ReplicatedStorage.FirePet


    local xPosition = char.Torso.Position.X
    local yPosition = char.Torso.Position.Y
    local zPosition = char.Torso.Position.Z

    local function AddFirePet()
        local FirePetCopy = FirePet:Clone()
        FirePetCopy.Parent = char.Torso

        wait(1)
        FirePetCopy.Position = Vector3.new(xPosition,yPosition,zPosition)
        print("Reset Positions")
    end

    -- I removed "do", you do not use it to call functions!
    AddFirePet()
end

Button.MouseButton1Click:connect(OnClicked)

Ad

Answer this question