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

Again, my script works in the studio but doesn't in the actual game, can somebody help?

Asked by
Echtic 128
5 years ago

Here's the script:


local me = game.Players.iiiAmericanLight local chr = me.CharacterAdded:Wait() local swr = game.ServerStorage["Meliodas Sword"] local pfr = game.ServerStorage.PurgatoryFlame local sw = swr:Clone() local pf = pfr:Clone() sw.Parent = me.Backpack pf.Parent = me.Backpack
0
If you give me the error message I can help. terence404 19 — 5y
0
There is no error message, works perfectly but only in studio Echtic 128 — 5y
0
Okay, so this means you'll have to fire an event scripting the sw and pf into 'me's' inventory. If this doesn't work, it's most likely because your game is FE. TheOnlySmarts 233 — 5y
0
When you make scripts they work as soon as the server starts running. In studio it waits for the client. To avoid things not loading in just add a wait function for 5 or 10 seconds at the start of each script. It really works. terence404 19 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

I hope this helps. It will replace some of your references so it waits for the child (yields until the child exists). Note: If you're using this in a LocalScript, you can't access ServerStorage from the LocalScript !!! You may want to use a RemoteEvent for it. If you are doing this for test purposes (Not recommended as the client can get the tools without any problem), you can try ReplicatedStorage, a container where both server and client replicate with.

local me = game.Players.iiiAmericanLight
local chr = me.Character or me.CharacterAdded:Wait()

local swr = game:GetService("ServerStorage"):WaitForChild("Meliodas Sword")
local pfr = game:GetService("ServerStorage"):WaitForChild("PurgatoryFlame")

local sw = swr:Clone()
local pf = pfr:Clone()

sw.Parent = me.Backpack
pf.Parent = me.Backpack

But, I'm sure you want it for practical purposes. Let's setup first your local side script. I'll explain the process below the codes. Here's the Local Script

-- LocalScript
local event = game:GetService("ReplicatedStorage"):WaitForChild("ClientRequest")
local player = game.Players.LocalPlayer
if player.Name == "iiAmericanLight" then -- you can try with userid instead, so it works regardless when you change of username.
    event:FireServer()
end

Here's the server script

-- ServerScript
local event = Instance.new("RemoteEvent")
event.Parent = game:GetService("ReplicatedStorage")
event.Name = "ClientRequest"

event.OnServerEvent:Connect(function(player)
    local swr = game:GetService("ServerStorage"):WaitForChild("Meliodas Sword")
    local pfr = game:GetService("ServerStorage"):WaitForChild("PurgatoryFlame")

    local sw = swr:Clone()
    local pf = pfr:Clone()

    sw.Parent = player.Backpack
    pf.Parent = player.Backpack
end)

What this actually does is, when the LocalScript runs (Supposedly you're using this LocalScript inside StarterGui), it assigns the player variable to the local player. then, through the if statement, it checks if the player's name is equal to the name you supposedly want to give such feature. and if it is, it then fires to the server through the remote connection we set up. Then in the ServerScript, it receives the interaction and since all client connections to the server return the player who effectuated the connection, we can use this for our server-side code. Now we can access ServerStorage and do our stuff! I've also removed your character variable as it wasn't needed but you can add it in your server-side script. The final stage is that the script gets the tools from the serverstorage, clones it and locates them in your Backpack. This also works with FilteringEnabled, as the work of each side belongs to their respective sides, that's it: server-sided tasks (accessing ServerStorage and distributing objects) must be in the server script, and local-side tasks (processing the request, setting up the stuff), must be in the local script! I hope it helped.

0
I do understand the concept, the only thing that bothers me is where should i put the server script? Echtic 128 — 5y
0
Nevermind, everything works perfectly! Echtic 128 — 5y
0
Thank You! :) Echtic 128 — 5y
Ad

Answer this question