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

Why does my tool only work on Player and not Server?

I have been trying to fix my tool that gives cash when u click it. But it doesnt work still, as an example, from my sight i see i have 100K moistbux and from others sight it says 0, heres my tool script, please answer if you can help me

local tool = script.Parent
reb = game.Players.LocalPlayer.leaderstats.moistbirths

function onActivation()
   game.Players.LocalPlayer.leaderstats.moistbux.Value = game.Players.LocalPlayer.leaderstats.moistbux.Value + 10e21 * reb.Value
   wait(0)
end
 
tool.Activated:connect(onActivation)

6 comments

0

You're doing that on the client.

0

First of all, :connect Is depricated ; use :Connect. And, is it a localscript?

0

its a local script and where should i put :Connect?

0

How do i make it not run on client?

0

:FireServer() :p

0

Where do i put :FireServer() ?

3 answers

###The reason it's doing that is because it is a LocalScript. It only runs on the client. Because of the new update that removed Experimental Mode, thus forcing FE, you'll need remote events and remote functions.

-- Server script, inside ServerScriptService

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local GiveMoney = ReplicatedStorage:WaitForChild("GiveMoney")-- RemoteEvent

GiveMoney.OnServerEvent:Connect(function(player)
    player.leaderstats.moistbux.Value = player.leaderstats.moistbux.Value + 10e21 * (player.leaderstats.moistbirths.Value)
end)

###Local script in the tool:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local GiveMoney = ReplicatedStorage:WaitForChild("GiveMoney")
local tool = script.Parent

function onActivation()
    GiveMoney:FireServer() -- get money 
   wait()
end

tool.Activated:Connect(onActivation) -- switch to :Connect, :connect is deprecated

1 comment

0

didnt work

Add a RemoteEvent in ReplicatedStorage

Call it "MoistBuxEvent"

Add a LocalScript in the tool

In the localscript:

local gimmemoistbux = game.ReplicatedStorage.MoistBuxEvent
function onActivation()
	gimmemoistbux:FireServer() -- everyone sees it after this
end

tool.Activated:Connect() -- "connect" is deprecated, recommended using "Connect"

In the serverscript:

-- exact same code but its fixed for FE
local gimmeitnow = game.ReplicatedStorage.gimmemoistbux

gimmeitnow.OnServerEvent:Connect(function(player)
reb = player.leaderstats.moistbirths

   player.leaderstats.moistbux.Value = player.leaderstats.moistbux.Value + 10e21 * reb.Value
   wait(0)

end

Took me like 10 mins to write this lol.

2 comments

0

It took me 15-20 mate

0

Didnt work either

Put in a local script in tool,

local tool = script.Parent
local player = game:GetService("Players")
local leaderstats = player:WaitForChild("leaderstats")
local bux = leaderstats:WaitForChild("moistbux")
local reb = leaderstats:WaitForChild("moistbirths")

function onActivation()
	bux.Value = bux.Value + 10e21 * reb.Value
	wait(0.1)
end

tool.Activated:Connect(onActivation)

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