I am having issues with a feature that allows a player to spend “points” to double their jump height. Here is the local script where the players jump height is doubled if they click the buy button: (local script located within textbutton in starterGui)
local shop=script.Parent
local plr=game.Players.LocalPlayer
local roundend=game.ReplicatedStorage.RoundEnd
local roundstart=game.ReplicatedStorage.RoundStart
local jumpheight2x=shop.JumpHeight2x
local character = plr.Character or plr.CharacterAdded:Wait()
local humanoid=character.Humanoid
local updatepoints=game.ReplicatedStorage.UpdatePoints
jumpheight2x.MouseButton1Click:Connect(function()
local points=plr.Points
if points.Value<50 then
print("Can't afford")
end
if points.Value>=50 then
humanoid.JumpHeight=14.4
updatepoints:FireServer(50)
end
end)
roundend.OnClientEvent:Connect(function()
shop.Enabled=true
humanoid.JumpHeight=7.2
end)
roundstart.OnClientEvent:Connect(function()
shop.Enabled=false
end)
and here is the server script that deducts the points from the player, and also updates the GUI that displays how many points they have: (located within ServerScriptService)
local updatepoints=game.ReplicatedStorage.UpdatePoints
local updatere=game.ReplicatedStorage.RoundEnd
updatepoints.OnServerEvent:Connect(function(plr, price)
local points=plr.Points
points.Value=points.Value-price
local newpoints=points.Value
updatere:FireClient(plr, newpoints)
end)
Ran like this, the points get deducted as they should, but the players jump height doesnt change. However if I remove the line
updatepoints:FireServer(50)
from the local script, the players jump height does change.
I have no idea why calling this RemoteEvent prevents the script from being able to change the jump height.
Are you sure? That aspect of the script works perfectly. The shop GUI continues to be enabled and disabled depending on whether there is an ongoing round or not.
Hmm. I mean, the only thing I can think of is that I’m manipulating stuff within the player in the server script while simultaneously trying to change the jump height in the local script? Doesn’t make much sense but maybe the requests are getting in each others way or something. I’ll try adding a buffer to the server script.
Would be great if you could, thanks a lot. Not gonna lie I don’t know what RemoteFunctions do differently, I’m very inexperienced and tend to just write code based off the few things that I know how to do
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local shop = script.Parent
local jumpHeight2x = shop:WaitForChild("JumpHeight2x")
local player = Players.LocalPlayer
local points = player:WaitForChild("Points")
local humanoid = (player.Character or player.CharacterAdded:Wait()):WaitForChild("Humanoid")
local remoteFunction = ReplicatedStorage:WaitForChild("RemoteFunction")
local debounce = false
local function onMouseButton1Click()
if debounce then return end
if points.Value >= 50 then
debounce = true
if remoteFunction:InvokeServer() then
print("Success!")
else
print("Can't afford")
end
debounce = false
else
print("Can't afford")
end
end
local function onCharacterAdded(character)
humanoid = character:WaitForChild("Humanoid")
end
jumpHeight2x.MouseButton1Click:Connect(onMouseButton1Click)
player.CharacterAdded:Connect(onCharacterAdded)
The new server Script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteFunction = ReplicatedStorage.RemoteFunction
local function onServerInvoke(player)
if not player.Character then return end
local points = player:FindFirstChild("Points")
if points and points.Value >= 50 then
points.Value -= 50
player.Character.Humanoid.JumpHeight *= 2
return true
end
end
remoteFunction.OnServerInvoke = onServerInvoke
I used a RemoteFunction with its default name inside of ReplicatedStorage
@BrainyBrian I’ve just made an important edit to the server Script
Just tested this is it seems to work, thanks!
Am I right in saying that using your system, I’ll need to have separate server scripts when I add different “powerups”? As the actual change to the jump height is now handled in the server script rather than the local script. edit: or perhaps just use different remote functions in the same server script?
I would suggest making separate functions and RemoteFunctions instead to keep your Explorer organized, as an example for a WalkSpeed powerup:
LocalScript:
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local shop = script.Parent
local jumpHeight2x = shop:WaitForChild("JumpHeight2x")
local walkSpeed2x = shop:WaitForChild("WalkSpeed2x")
local player = Players.LocalPlayer
local points = player:WaitForChild("Points")
local humanoid = (player.Character or player.CharacterAdded:Wait()):WaitForChild("Humanoid")
local jumpHeight2xRF = ReplicatedStorage:WaitForChild("JumpHeight2xRF")
local walkSpeed2xRF = ReplicatedStorage:WaitForChild("WalkSpeed2xRF")
local debounce1, debounce2 = false, false
local function onjumpHeight2xClick()
if debounce1 then return end
if points.Value >= 50 then
debounce1 = true
if jumpHeight2xRF:InvokeServer() then
print("Success!")
else
print("Can't afford")
end
debounce1 = false
else
print("Can't afford")
end
end
local function onWalkSpeed2xClick()
if debounce2 then return end
if points.Value >= 100 then
debounce2 = true
if walkSpeed2xRF:InvokeServer() then
print("Success!")
else
print("Can't afford")
end
debounce2 = false
else
print("Can't afford")
end
end
local function onCharacterAdded(character)
humanoid = character:WaitForChild("Humanoid")
end
jumpHeight2x.MouseButton1Click:Connect(onjumpHeight2xClick)
walkSpeed2x.MouseButton1Click:Connect(onWalkSpeed2xClick)
player.CharacterAdded:Connect(onCharacterAdded)
Server:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local jumpHeight2xRF = ReplicatedStorage.JumpHeight2xRF
local walkSpeed2xRF = ReplicatedStorage.WalkSpeed2xRF
local function onJumpHeight2xRFInvoke(player)
if not player.Character then return end
local points = player:FindFirstChild("Points")
if points and points.Value >= 50 then
points.Value -= 50
player.Character.Humanoid.JumpHeight *= 2
return true
end
end
local function onWalkSpeed2xRFInvoke(player)
if not player.Character then return end
local points = player:FindFirstChild("Points")
if points and points.Value >= 100 then
points.Value -= 100
player.Character.Humanoid.WalkSpeed *= 2
return true
end
end
jumpHeight2xRF.OnServerInvoke = onJumpHeight2xRFInvoke
walkSpeed2xRF.OnServerInvoke = onWalkSpeed2xRFInvoke