February 23, 2022, 10:23am
Hey I’m wisematheu,
I’ve got this error that comes up when I click the button (please see images below) and it says ‘Unable to cast value to Object’ but I think the variables I put in the brackets do have values so I’m a bit confused.
Script inside a textbutton inside of a surfacegui in workspace
Local script inside starterplayerscripts under starterplayer
local event = game.ReplicatedStorage.MachineOrderEvents.Burger
local button = script.Parent
local orderNumber = game.ServerStorage.Ordernumber.Value
game.ServerStorage.Ordernumber.Value = game.ServerStorage.Ordernumber.Value + 1
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local player = Players.LocalPlayer
local events = ReplicatedStorage:WaitForChild("MachineOrderEvents")
burgerEvent = events.Burger
Mind sending a screenshot of what’s under
Player is already automatically sent any value in the parameters is what’s next so the script thinks that the player is the ordernumber value
Just remove the player parameter
hi, can u show images of the hierarchy for the gui (and script)
Pretty sure this is correct solution.
wait I’m confused, which line of code are u telling him to remove ‘player’ from
February 23, 2022, 12:13pm
I think line 7 and 5 of the server script (first image)
Line seven in the server script
But if he’s using FireClient, player is needed to define who is receiving the call
Oopsies, true… so it’s not that. Hm.
What type of value is Ordernumber?
Also assuming burgerEvent is a remoteevent,
you don’t need to return anything in the OnClientEvent
Also another word of disclaimer, you should put any interactable surfaceguis inside PlayerGui and adornee them to the part
I didnt think of that at all I don’t use fireclient often
Is the GUI a child of a part in the workspace? Please send a screenshot of its location.
It is, I believe he’s trying to use MouseButton1Up on the server, while he should be doing anything user input based on the client
February 23, 2022, 12:20pm
The value of Ordernumber is an integar and I’ve now put the surfacegui inside the startgui
February 23, 2022, 12:21pm
Hi, now it’s a child of startergui
Change it to a localscript now and you dont need to use a remoteevent at all
Great! That’s likely the issue. You cannot execute scripts in a GUI that is under a part of the workspace.
Edit: Nevermind, do what @InedibleGames is saying. Didn’t realise it was a
February 23, 2022, 12:23pm
I’ll test it when I’ve created a script in serverscriptservice brb