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

How to change this local script into a normal script?

Asked by 5 years ago

I don't know what to do with this script, it's really ruining my leaderboard values

script.Parent.MouseButton1Click:connect(function()
    local p = game.Players.LocalPlayer
    local s = script.Parent.Sound
    s:Play()
    p.leaderstats.Bux.Value = p.leaderstats.Bux.Value + 1
    local o = game.ReplicatedStorage.One:clone()
    o.Parent = p.PlayerGui
    o.TextLabel:TweenPosition(UDim2.new(0.61, 0,0.661, 0), 'Out', 'Bounce', 1.5)
    wait(1)
    o:Destroy()
end)

1 answer

Log in to vote
1
Answered by
HaveASip 494 Moderation Voter
5 years ago
Edited 5 years ago

You need to use remote events. Insert script in serverscriptservice and type this...

--[[Server Script]]--

local Event = Instance.new("RemoteEvent")
Event.Parent = game:GetService("ReplicatedStorage")
Event.Name = "TestEvent"

Event.OnServerEvent:Connect(function(player, bux) --player who fired, bux is cost of bux
    local stats = player.leaderstats
    stats.Bux.Value = stats.Bux.Value + bux
end)

and here is your fixed localscript

--[[ LocalScript ]]--

local Event = game:GetService("ReplicatedStorage").TestEvent

script.Parent.MouseButton1Click:connect(function()
    local p = game.Players.LocalPlayer
    local s = script.Parent.Sound
    s:Play()
    Event:FireServer(1) -- 1 is bux value what we firing to server
    local o = game:GetService("ReplicatedStorage"):WaitForChild("One"):Clone()
    o.Parent = p.PlayerGui
    o.TextLabel:TweenPosition(UDim2.new(0.61, 0,0.661, 0), 'Out', 'Bounce', 1.5)
    wait(1)
    o:Destroy()
end)


Ad

Answer this question