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

Value is not a valid member of player?

Greetings,

I've got an error while scripting the server side of my gun shop, this is the server script:

--[[
	By Time_URSS
	Server-sided Gun shop
--]]

--//Variables\\--
local replicatedStorage = game:GetService("ReplicatedStorage")
local remoteFunction = replicatedStorage:WaitForChild("Buy")

--//Functions\\--
remoteFunction.OnServerEvent:Connect(function(player,price,gun)
	player.leaderstats.Rubbles.Value = player.leaderstats.Rubbles.Value - price.Value
	local clonedGun = gun:Clone()
	clonedGun.Parent = player.Backpack
	print("Gun successfully bought, transaction successful.")
end)

This is the client sided script:

--[[
	Script made by: Time_URSS
	Client-sided gun shop
--]]

--//Variables\\--
local player = game.Players.LocalPlayer
local button = script.Parent
local name = button:WaitForChild("FinalName")
local price = button:WaitForChild("FinalPrice")
local nameText = button.Parent.Name
local priceText = button.Parent.Price
local replicatedStorage = game:GetService("ReplicatedStorage")
local remoteFunction = replicatedStorage:WaitForChild("Buy")

--//Functions\\--
local function buyProcess()
	local weapon = replicatedStorage:WaitForChild("Guns"):FindFirstChild(name.Value)
	if weapon then
		if player.leaderstats.Rubbles.Value >= price.Value then
			remoteFunction:FireServer(player,price.Value,weapon)
		else
			warn("Player does not have enough Rubbles to buy the gun. Wait until you've enough.")
		end
	else
		error("Weapon not found, please contact Time_URSS to fix the error. ERROR#050")
	end
end

button.MouseButton1Click:Connect(buyProcess)

And this is the error:

11:59:47.653 - Value is not a valid member of Player
11:59:47.655 - Stack Begin
11:59:47.656 - Script 'ServerScriptService.BuyProcess', Line 12
11:59:47.656 - Stack End

Can somebody help me?

1 answer

✓ Accepted answer

You don't need to send the "Player" Arguments through the local script when you are firing the remote function as the player is always the first argument by default on the script that picks up the remote function or remote event instead just send the price and weapon like i have done below.

--[[
    Script made by: Time_URSS
    Client-sided gun shop
--]]

--//Variables\\--
local player = game.Players.LocalPlayer
local button = script.Parent
local name = button:WaitForChild("FinalName")
local price = button:WaitForChild("FinalPrice")
local nameText = button.Parent.Name
local priceText = button.Parent.Price
local replicatedStorage = game:GetService("ReplicatedStorage")
local remoteFunction = replicatedStorage:WaitForChild("Buy")

--//Functions\\--
local function buyProcess()
    local weapon = replicatedStorage:WaitForChild("Guns"):FindFirstChild(name.Value)
    if weapon then
        if player.leaderstats.Rubbles.Value >= price.Value then
            remoteFunction:FireServer(price.Value,weapon)
        else
            warn("Player does not have enough Rubbles to buy the gun. Wait until you've enough.")
        end
    else
        error("Weapon not found, please contact Time_URSS to fix the error. ERROR#050")
    end
end

button.MouseButton1Click:Connect(buyProcess)

1 comment

0

I see, thank you!

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