I’m creating a lifting simulator game and I’ve been having trouble with the rebirth. When you rebirth, the value,
player.BodyStrengthMultiplyer.Value
is supposed to multiply the value,
player.WeightPerLift.Value
I’ve tried triggering a remote event from a local script, and enabling and disabling a script but it doesn’t seem to work whenever I use this either this script,
game.ReplicatedStorage.purchaseRank.OnServerEvent:Connect(function()
local player = game:GetService("Players").PlayerAdded:Wait()
player.WeightPerLift.Value = player.WeightPerLift.Value * player.BodyStrengthMultiplyer.Value
end)
or,
local player = game:GetService("Players").PlayerAdded:Wait()
player.WeightPerLift.Value = 1 * player.BodyStrengthMultiplyer.Value
wait(1)
script.Disabled = true
Both of these cases the value won’t multiply (for example {BodyStrengthMultiplyer = 4
and WeightPerLift = 2} so WeightPerLift = 8)
The PlayerAdded event fires when a player joins the game, so calling game:GetService("Players").PlayerAdded:Wait() will wait for a player to join and then multiply that new player’s strength.
Conveniently, remotes automatically pass the player that fired them into the function.
Try this:
game.ReplicatedStorage.purchaseRank.OnServerEvent:Connect(function(player) -- player is automatically provided whenever the remote is fired
player.WeightPerLift.Value *= player.BodyStrengthMultiplyer.Value -- "x *= y" is identical to "x = x * y". +=, -=, /= and %= also work.
end)
A side note: Since you’re not actually checking if the player can rebirth on the server, an exploiter could just fire this remote and rebirth as many times as they wanted to, even if they don’t meet the requirements. You’ll want to add checks to make sure they’re allowed to rebirth before giving them their reward.
I actually fixed it, I realized I had to use a local script instead of a script by triggering the
FireServer()
and in a script (this is my strength capacity script),
game.ReplicatedStorage.StrengthData.RemoteEvent.OnServerEvent:Connect(function(Player)
if Player.leaderstats.Strength.Value < Player.PlayerCapacity.Value then
game.ReplicatedStorage.StrengthData.RemoteEvent:FireClient(Player)
else if Player.leaderstats.Strength.Value >= Player.PlayerCapacity.Value then
game.ReplicatedStorage.StrengthData.ReachedCapacity:FireAllClients()
end
end
end)
which fires the client and I put this into a local script,
game.ReplicatedStorage.StrengthData.RemoteEvent.OnClientEvent:Connect(function(Player)
if Player.leaderstats.Strength.Value < Player.PlayerCapacity.Value then
Player.leaderstats.Strength.Value += (Player.WeightPerLift.Value * Player.BodyStrengthMultiplyer.Value)
end
end)
I’m working on a way to detect if the player is eligible to rebirth to prevent exploiters.