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

Server script cannot find the parent of an object?

Asked by 3 years ago

Ok so I have an object value called "Weapon" and inside of my local script I fire a remote event carrying the weapons value. Now when the server script gets the event and the data with it it cannot find the parent of the parent of object which is the player and I dont think it finds the object either.

This is my local script in the players gui.

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local remoteEvent = ReplicatedStorage:WaitForChild("UpgradeEvent")

function onClicked()
    local Weapon = script.Parent.Parent.Weapon.Value
    print ("EventSent")
remoteEvent:FireServer(Weapon)
end
script.Parent.MouseButton1Down:connect(onClicked)

This is my server script in serverscriptservice.

local remoteEvent = game.ReplicatedStorage.UpgradeEvent
local function Upgrade(Weapon)
    print ("Event Recieved")
    local player = Weapon.Parent.Parent
    if player.leaderstats.Money.Value >= 100 then
        player.leaderstats.Money.Value =  player.leaderstats.Money.Value - 100
        print ("Player has enough money")
        local updmg = Weapon.Damage / 5
        Weapon.Damage = Weapon.Damage + updmg
        print ("Upgrade Amount"..updmg)
    else

    end
end

remoteEvent.OnServerEvent:Connect(Upgrade)

This is the error I get because instead of searching for leaderstats in the player it searches for it in the game. Even though in the server script it clearly says

Player = Weapon.Parent.Parent

which if we check in client mode is the player.

error:

leaderstats is not a valid member of DataModel "Battle Ultimates"

The local script does not give any errors as it prints out "Event Sent" and the server script gets the event as it prints out "Event Recieved" But it does not print out the other parts because the error is on line 7 now the error would not happen if it actually understood where player was.

0
When you play test in studio you can see the player holding the gun right? If you go to the server view is the player still holding the gun? AlexTheCreator 461 — 3y
0
Well I havent actually made the gun model yet its just a part it does not hold it. In client mode AND server mode you can see the gun in the players custom inventory folder epicnmac 63 — 3y

Answer this question