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

LocalScript won't require from ServerStorage, how do I get around this?

The GUI is supposed to add one point each time it's clicked but It's not working. I think it won't work because I'm trying to require something from the ServerStorage in a LocalScript. Is there any work-around for this?

local DataStore2 = require(game.ServerScriptService.StatsDataStore2:WaitForChild("MainModule"))
local Player = game.Players.LocalPlayer

function onclick()

		local PointsStore = DataStore2("Points", Player)
		PointsStore:Increment(1)	

end

script.Parent.MouseButton1Click:connect(onclick)

2 answers

LocalScripts do not have access to ServerStorage and ServerScriptService because these are only viewable by the server, consider putting your module in ReplicatedStorage or ReplicatedScriptService.

4 comments

0

Also, datastores cant be used from LocalScripts

0

So basically this will never work and there's no way around it?

0

There is a way around it. Check this out (https://scriptinghelpers.org/guides/server-client-relationship-in-roblox) for more information

I will answer this question, but you do need to learn about remote events (and ideally remote functions too). Without them it is almost impossible to make a proper game on roblox these days.

First step, create a new script (not local) in ServerScriptService:

local IncreasePointsEvent = Instance.new("RemoteEvent")
IncreasePointsEvent.Name = "IncreasePointsEvent"
IncreasePointsEvent.Parent = game.ReplicatedStorage

local DataStore2 = require(game.ServerScriptService.StatsDataStore2:WaitForChild("MainModule"))

function onIncreasePointsEvent(player,amount)

        local PointsStore = DataStore2("Points", player)
        PointsStore:Increment(amount)    

end
IncreasePointsEvent.OnServerEvent:Connect(OnIncreasePointsEvent)

Then modify Your localScript like this:

local IncreasePointsEvent = game.ReplicatedStorage:WaitForChild("IncreasePointsEvent")

function onclick()

	IncreasePointsEvent:FireServer(1)

end

script.Parent.MouseButton1Click:connect(onclick)

Hope this helps, have a nice scripting session.

2 comments

0

I appreciate your help but this didn't work :(

0

any errors?

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