[Solved] Help on scripting a boat shop

What do I want to achieve?

I want to achieve a boat shop like the one in shark bite I can’t seem to work it out though.

What is the issue?

I won’t change the Boat Value in Workspace (As this will be a one-player game)

What solutions have you tried so far?

I have tried everything I can and it won’t work.

local Stats = game.Players.LocalPlayer.leaderstats
local Money = Stats:WaitForChild("Money")

script.Parent.MouseButton1Down:Connect(function()
	if Money.Value >= 400 then
		game.Workspace.Boat.Value = game.ReplicatedStorage:WaitForChild("Ship2")
		Money.Value = Money.Value - 400
	else
	    print("400 money needed")
	end
end)

Heres a screenshot of the layout of the gui in StarterGui image

3 Likes

A few things I notice:

  • You are using ImageLabels instead of ImageButtons
  • The stats variable can be shortened.
  • You are trying to change a workspace value with a client script.
  • You are using a regular script instead of a LocalScript on the client.

How you can clean up the code:

local Stats = game.Players.LocalPlayer.leaderstats
local Money = Stats:WaitForChild("Money")

script.Parent.MouseButton1Down:Connect(function()
	if Money.Value >= 400 then
		game.Workspace.Boat.Value = game.ReplicatedStorage:WaitForChild("Ship2")
		Money.Value = Money.Value - 400
	else
	    print("400 money needed")
	end
end)
5 Likes

Should I mark this as a solution if it works?

Yes if its works then mark it as a solution

1 Like

It won’t change still. (30 chars)

I would use MouseButton1Click, and use a remote function to check on the server side if the player has money or not. Also any change you make to the game must be made by the server rather than client. Since exploiters can easily change stuff on the client.

Edit : If youre not familiar with filtering enabled, I’d suggest you to study further about it as it plays a huge role in a game’s security. You can also learn more about it here : https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events

1 Like

How? (30 chars) (30 chars) (30 chars)

I’d suggest learning a bit more about server-client architecture and coding it. I will not provide any coding examples since there are plenty enough resources to learn from.

1 Like

He is literally changing values on the client. Which should be done on the server. This may be the reason it won’t work

1 Like

You can’t store objects in a any sort of value.

I’m assuming you have a StringValue inside the Boat and if not you can just add a StringValue then set that value to the ship’s name.

Ex:

local Stats = game.Players.LocalPlayer.leaderstats
local Money = Stats:WaitForChild("Money")

script.Parent.MouseButton1Down:Connect(function()
	if Money.Value >= 400 then
		game.Workspace.Boat.Value = game.ReplicatedStorage:WaitForChild("Ship2").Name
		Money.Value = Money.Value - 400
	else
	    print("400 money needed")
	end
end)
1 Like

ObjectValue. (30 chars) (30 chars)

Ahaha my mistake I forgot that existed. Then your current script will work but it won’t replicate to the server. That’s probably your problem.

1 Like

I need the respawn boat script to see it.

Here is the issue that I notice:

You are trying to do this:

Money.Value = Money.Value - 400

On the client. If the player leaves the game, then comes back, then their cash will stay the same. And hackers can literally remove that one line of code, and allow them to get their boat for free.

Here is another issue:

From my understanding you are trying to give the player their boat here:

game.Workspace.Boat.Value = game.ReplicatedStorage:WaitForChild("Ship2").Name

You should instead be giving the player their boat on the server.


If you don’t know how to do this, I suggest you watch a couple of videos that teach you how to use remote events, and remote functions:

1 Like

In case anyone has a similar problem the error was in the first line because the script replicated before the leaderstats.

local Stats = game.Players.LocalPlayer:WaitForChild("leaderstats")
2 Likes