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

How do i make remote events to change my stats?

I'm new to remote events and these other things so, i forgot how to use them. I made a part that functions when touched and fires the event db = false script.Parent.Touched:connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then local player = game.Players:GetPlayerFromCharacter(hit.Parent) if db == false then db = true game.ReplicatedStorage.Events.getgift:FireServer() wait(20) db = false elseif db == true then game.StarterGui:SetCore("SendNotification", { Title = "Too fast"; Text = "Please wait to get gifts again."; Icon = ""; Duration = 3; }) end end end) then i made a script that connects a function on server event and gives stats local player = game.Players.LocalPlayer game.ReplicatedStorage.Events.getgift.OnServerEvent:Connect(function() player.Stats.Gifts.Value = 109209090990090909 wait (20) end)

but it didnt work so yeah help? i want that only to work on a person that fires that event

1 comment

0

it may not be pasted perfectly

1 answer

✓ Accepted answer

You posted your code all bunched up so it's hard to read, but here is how you use a Remote Event to solve your problem, assuming the problem is just that you want to change a players stat when the said part is touched by that player: For this example, I have a Part named "Part" in the workspace, a Remote Event named "Touched" in ReplicatedStorage, two Scripts inside of ServerScriptService, one for setting up the leaderboard and another for handling the Remote Event, and a Local Script inside of StarterPlayerScripts. Local Script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local touchedEvent = ReplicatedStorage:WaitForChild("Touched")
local player = game:GetService("Players").LocalPlayer
local part = workspace.Part -- rename this variable to whatever you want and locate the part you want to have fire the event when it is touched
local debounce = true -- optional, but recommended
part.Touched:Connect(function()
    if debounce == true then
	    debounce = false
	    touchedEvent:FireServer() -- automatically sends the "LocalPlayer" as the first parameter
	    wait(1) -- for debounce
	    debounce = true
	end
end)

Remote Event Handler Script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local touchedEvent = ReplicatedStorage:WaitForChild("Touched")
local function onTouchedEventFired(player)
    local money = player.leaderstats.Money
    money.Value = money.Value + 1 -- adds however much money you want to the players money
end
touchedEvent.OnServerEvent:Connect(onTouchedEventFired)

Simple Leaderstats Script:

local function onPlayerJoin(player)
    local leaderstats = Instance.new("Folder", player)
    leaderstats.Name = "leaderstats"
    local money = Instance.new("IntValue", leaderstats)
    money.Name = "Money"
    money.Value = 0
end
game:GetService("Players").PlayerAdded:Connect(onPlayerJoin)

Please let me know if this isn't the answer you were looking for, I would be glad to try and fix it! Hope this helps!

1 comment

0

Thanks

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