Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago

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)
0
You're doing that on the client. User#19524 175 — 6y
0
First of all, :connect Is depricated ; use :Connect. And, is it a localscript? AltNature 169 — 6y
0
its a local script and where should i put :Connect? SamirDevs 15 — 6y
0
How do i make it not run on client? SamirDevs 15 — 6y
View all comments (2 more)
0
:FireServer() :p superender11 -17 — 6y
0
Where do i put :FireServer() ? SamirDevs 15 — 6y

3 answers

Log in to vote
0
Answered by 6 years ago

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

0
didnt work SamirDevs 15 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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.

0
It took me 15-20 mate User#19524 175 — 6y
0
Didnt work either SamirDevs 15 — 6y
Log in to vote
0
Answered by 6 years ago

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)

Answer this question