When I press Return/Enter, this script fires a RemoteEvent thats in ReplicatedStorage.
LocalScript in StarterCharacter:
local UserInputService = game:GetService("UserInputService")
local Event = game.ReplicatedStorage:WaitForChild("StartGame")
UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.Keyboard then
if Enum.KeyCode.Return then
Event:FireServer()
end
end
end)
ServerScript in ServerScriptService:
local Event = game.ReplicatedStorage.StartGame
local SGui = game.StarterGui
local player = game.Players.LocalPlayer
local H = player.Character.Humanoid
Event.OnServerEvent:Connect()
print("Works?")
SGui.FreezePlayer.Enabled = false
H.WalkSpeed = 75
H.JumpPower = 100
There’s a couple of weird things going on in your script.
Why are you defining a new variable using UserInputService if you already defined it 2 lines beforehand.
You’re not checking if the the GameProcessed boolean is true/enabled, and you’re not checking to see if the keycode the user clicked is the Return/Enter key.
You’re trying to get the LocalPlayer from the server. The LocalPlayer means the player local to the client that’s running Roblox (You can only get LocalPlayer from a LocalScript).
You’re using StarterGui. The content the player sees on their screen is replicated to the player’s PlayerGui. Modifying StarterGui doesn’t change anything on the player’s screen.
You never connected a function to the RemoteEvent.
Your LocalScript should look like this:
local UserInputService = game:GetService("UserInputService")
local Event = game.ReplicatedStorage:WaitForChild("StartGame")
local PlayerGui = game:GetService("Players").LocalPlayer:WaitForChild("PlayerGui")
-- get the player's screen content
UserInputService.InputBegan:Connect(function(input, processed)
if input.UserInputType == Enum.UserInputType.Keyboard and not processed then
-- check if the player isn't typing anything
if input.KeyCode == Enum.KeyCode.Return then -- check if the player pressed this key
Event:FireServer()
-- change the player's screen from the client
PlayerGui:WaitForChild("FreezePlayer").Enabled = true -- enable the ScreenGui
end
end
end)
And your ServerScript should look like this:
local Event = game.ReplicatedStorage.StartGame
Event.OnServerEvent:Connect(function(player) -- connect a function to the signal
local humanoid = player.Character:FindFirstChildOfClass("Humanoid")
if not humanoid then -- if the player's humanoid didn't load
return -- stop the functiuon
end
humanoid.WalkSpeed = 75
humanoid.JumpPower = 100
end)