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

StarterGui is not a valid member of model?

I'm trying to make a script where when a player clicks on another player they can sell an item. I've got this as a local script under StarterPlayerScripts:

local Player = game.Players.LocalPlayer -- Getting the player   
local Mouse = Player:GetMouse() -- Getting the players mouse


Mouse.Button1Down:Connect(function() -- Detecting when player presses the left mouse button
	
    if Mouse.Target.Parent:FindFirstChild("Humanoid") and 
        game.Players.LocalPlayer.TeamColor.Name == ("Dirt brown") then -- Checking if the Mouse is over a player
        print(Mouse.Target.Parent.Name) 
	local mousetarget = Mouse.Target.Parent
		game.ReplicatedStorage.SellPistol:FireServer(mousetarget)
		
	


    end
end)

Then I have this script under ServerScriptService:

local SellPistol = game.ReplicatedStorage.SellPistol

local function onSellPistol(player, mousetarget)
    mousetarget.StarterGui.StartScreen.Frame.Visible = true
print("Debug")
end






SellPistol.OnServerEvent:Connect(onSellPistol)

When i click on another player I get this:

StarterGui is not a valid member of model

Did I use the parameter wrong?

1 comment

0

mayb if ur good at scripting u wldnt have to ask this questions

1 answer

✓ Accepted answer

Yes because you're giving the server mouse.Target.Parent so the player's model not a player and startergui is only registered as in-game roblox itself users have a thing called "playergui" here you go fixed:

local SellPistol = game.ReplicatedStorage.SellPistol

local function onSellPistol(player, mousetarget)
    local target = game:GetService("Players")[mousetarget.Name]
    target .PlayerGui.StartScreen.Frame.Visible = true
    print("Debug")
end

SellPistol.OnServerEvent:Connect(onSellPistol)

You could also use :

local SellPistol = game.ReplicatedStorage.SellPistol

local function onSellPistol(player, mousetarget)
    local target = game:GetService("Players"):GetPlayerFromCharacter(mousetarget)
    target .PlayerGui.StartScreen.Frame.Visible = true
    print("Debug")
end

SellPistol.OnServerEvent:Connect(onSellPistol)

Comment if there's any errors, thank you.

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