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

Tool specific RemoteEvent?

Asked by 5 years ago

Hi, so I have a RemoveEvent setup so that when someone swings a sword (any sword) it will give them +25xp. However, I am trying to make each sword give a different amount. So Sword A will give +25 per swing, and Sword B will give +50 per swing etc.

Script inside ServerScriptService:

local replicatedStorage = game:GetService("ReplicatedStorage")
local remoteData =  game:GetService("ServerStorage"):WaitForChild("RemoteData")

local cooldown = 0.85

replicatedStorage.Remotes.Swing.OnServerEvent:Connect(function(player)

if not remoteData:FindFirstChild(player.Name) then return "NoFolder" end

local debounce = remoteData[player.Name].Debounce

if not debounce.Value then

debounce.Value = true

player.leaderstats.XP.Value = player.leaderstats.XP.Value + 25

player.leaderstats["Strength"].Value = player.leaderstats["Strength"].Value + 25

wait(cooldown)

debounce.Value = false

end

end)

This is the ModuleScript inside the all the swords I have so far:

local module = {}

local replicatedStorage = game:GetService("ReplicatedStorage")

function module.Swing()

    replicatedStorage.Remotes.Swing:FireServer()

end

return module

and here is the LocalScript I have inside all the swords I have so far:

local module = require(script.Parent:WaitForChild("ModuleScript"))
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

script.Parent.Activated:Connect(function()

    module.Swing()

end)

Do I have to make different swing events for all the different swords?

Or is there a better method I could use here?

Thanks!

0
You can fire with the :FireServer() function the amount of XP the used sword is gonna give. And work it out that way, I don't think there's a need for more remotes, that will still work but it's unneficient. starmaq 1290 — 5y
0
So the local script inside Sword A will have module.Swing(50) and each sword will have his own amount of XP starmaq 1290 — 5y
0
And ofc add the XP paramater in the Swing function in the module starmaq 1290 — 5y
0
So.. I'm not that experienced with this (just saying before hand). I've added the XP giver into the module script with FireServer() and it is only giving xp with that sword which is great. But how do I implement my debounce with that as well? It seemed to break, when I attempted to add it in there as well. Still tryna wrap my head around all of this. topogigio 9 — 5y
0
Nevermind, I got the debounce to work. Thanks for the suggestion btw. topogigio 9 — 5y

Answer this question